MCQs on Introduction to TypeScript | TypeScript

TypeScript is a powerful, statically-typed superset of JavaScript that enhances development by adding type safety and modern features. It improves code quality, debugging, and scalability, making it ideal for large-scale applications. This guide covers TypeScript fundamentals, benefits over JavaScript, setup, and compilation.


Multiple Choice Questions (MCQs)

Section 1: What is TypeScript?

  1. TypeScript is a superset of which programming language?
    a) Python
    b) Java
    c) JavaScript
    d) C#
  2. Who developed TypeScript?
    a) Google
    b) Facebook
    c) Microsoft
    d) IBM
  3. Which of the following is true about TypeScript?
    a) It is a backend language
    b) It is an extension of HTML
    c) It provides optional static typing
    d) It is only for front-end development
  4. What file extension is used for TypeScript files?
    a) .ts
    b) .tsx
    c) .js
    d) .jsx
  5. TypeScript was introduced in which year?
    a) 2010
    b) 2012
    c) 2014
    d) 2016
  6. Which feature of TypeScript helps in finding bugs during development?
    a) Dynamic typing
    b) Static typing
    c) Loose typing
    d) Strong typing
  7. How does TypeScript handle JavaScript code?
    a) Converts JavaScript code to TypeScript
    b) Ignores JavaScript code
    c) Runs JavaScript code directly
    d) Transpiles JavaScript to TypeScript

Section 2: Benefits of TypeScript over JavaScript

  1. What is one of the main benefits of using TypeScript over JavaScript?
    a) Faster execution time
    b) Less code required
    c) Enhanced code readability and maintainability
    d) Better browser compatibility
  2. TypeScript helps in reducing bugs by providing which feature?
    a) Syntax highlighting
    b) Type inference
    c) Contextual typing
    d) Source maps
  3. Which of the following is NOT a benefit of using TypeScript?
    a) Optional static typing
    b) Better tooling with editors
    c) Enhanced CSS integration
    d) Object-oriented programming features
  4. How does TypeScript improve team collaboration?
    a) By enforcing coding standards
    b) By reducing file sizes
    c) By providing type annotations
    d) By allowing runtime checks
  5. TypeScript code needs to be compiled into which format to run in browsers?
    a) Python
    b) Java
    c) JavaScript
    d) C++
  6. How does TypeScript enhance the development process?
    a) By enabling machine learning features
    b) By adding static type-checking
    c) By integrating with SQL databases
    d) By improving network latency
  7. TypeScript supports which of the following programming paradigms?
    a) Functional
    b) Object-oriented
    c) Procedural
    d) All of the above
  8. What tool in TypeScript helps catch errors before runtime?
    a) Type checker
    b) Linter
    c) Debugger
    d) Profiler

Section 3: Setting up a TypeScript Development Environment

  1. Which command is used to install TypeScript globally via npm?
    a) npm install -g typescript
    b) npm install typescript –save
    c) npm init typescript
    d) npm start typescript
  2. What file is used to configure TypeScript settings?
    a) package.json
    b) tsconfig.json
    c) typescript.json
    d) config.json
  3. Which editor is commonly used for TypeScript development due to its rich support and extensions?
    a) Notepad++
    b) Eclipse
    c) Visual Studio Code
    d) Sublime Text
  4. To compile TypeScript code into JavaScript, which command is used?
    a) ts-run
    b) ts-compile
    c) tsc
    d) tsbuild
  5. How can you watch for changes in your TypeScript files and recompile automatically?
    a) tsc -auto
    b) tsc –watch
    c) tsc -monitor
    d) tsc –auto
  6. The command tsc --init is used for what purpose?
    a) To start a new TypeScript project
    b) To install TypeScript dependencies
    c) To create a tsconfig.json file
    d) To upgrade TypeScript version
  7. What is the purpose of the outDir option in tsconfig.json?
    a) Specify TypeScript version
    b) Define output directory for compiled JavaScript files
    c) Include additional libraries
    d) Enable debugging

Section 4: TypeScript Compiler (tsc) and Configuration

  1. What does the strict option in tsconfig.json do?
    a) Enables strict mode for JavaScript
    b) Ensures all files are compiled
    c) Applies strict type-checking rules
    d) Makes TypeScript compilation faster
  2. How can you exclude files from being compiled by TypeScript?
    a) Using the ignore option
    b) Using the exclude option
    c) Using the remove option
    d) Using the hide option
  3. Which of the following compiles only one specified TypeScript file?
    a) tsc –all
    b) tsc [filename].ts
    c) tsc –file [filename]
    d) tsc -single [filename]
  4. How can you enable ES6 features in TypeScript?
    a) Set “target” to “ES5”
    b) Set “target” to “ES6”
    c) Set “lib” to “ES6”
    d) Use “es6” command
  5. What does the noImplicitAny option enforce?
    a) Disallows the use of any variable
    b) Disallows variables with type any
    c) Enables automatic type inference
    d) Forces strict null checks
  6. How do you specify multiple files for TypeScript to compile in tsconfig.json?
    a) Using the include array
    b) Using the files array
    c) Using the compile array
    d) Using the input array
  7. Which flag helps in debugging TypeScript code by generating source maps?
    a) –debug
    b) –sourceMaps
    c) –map
    d) –trace
  8. If you want to compile TypeScript files into a specific version of ECMAScript, which option would you use?
    a) –ecma-version
    b) –compile-version
    c) –target
    d) –version

Answers

QnoAnswer
1c) JavaScript
2c) Microsoft
3c) It provides optional static typing
4a) .ts
5b) 2012
6b) Static typing
7c) Runs JavaScript code directly
8c) Enhanced code readability and maintainability
9b) Type inference
10c) Enhanced CSS integration
11c) By providing type annotations
12c) JavaScript
13b) By adding static type-checking
14d) All of the above
15a) Type checker
16a) npm install -g typescript
17b) tsconfig.json
18c) Visual Studio Code
19c) tsc
20b) tsc –watch
21c) To create a tsconfig.json file
22b) Define output directory for compiled JavaScript files
23c) Applies strict type-checking rules
24b) Using the exclude option
25b) tsc [filename].ts
26b) Set “target” to “ES6”
27b) Disallows variables with type any
28a) Using the include array
29b) –sourceMaps
30c) –target

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top