TypeScript Quiz

TypeScript adds static types to JavaScript to catch mistakes before code runs. The quiz covers basic types, interfaces, generics, enums, classes and how TypeScript compiles to plain JavaScript.

What this quiz covers

Study tip: Turn on strict mode in a small project; the compiler messages teach you the type rules as you go.

Questions, answers and explanations

1. What is TypeScript?

  1. A JavaScript library
  2. A superset of JavaScript
  3. A CSS framework
  4. A database

Answer: A superset of JavaScript

TypeScript is a strongly typed superset of JavaScript developed by Microsoft.

2. Who developed TypeScript?

  1. Google
  2. Microsoft
  3. Facebook
  4. Oracle

Answer: Microsoft

TypeScript was developed and is maintained by Microsoft.

3. Which file extension is used for TypeScript files?

  1. .ts
  2. .js
  3. .tsxx
  4. .type

Answer: .ts

TypeScript source files use the .ts extension.

4. Which command compiles a TypeScript file?

  1. tsc
  2. ts
  3. compile
  4. npm compile

Answer: tsc

The TypeScript compiler is called using the 'tsc' command.

5. Which keyword is used to declare a variable in TypeScript?

  1. let
  2. var
  3. const
  4. All of the above

Answer: All of the above

TypeScript supports var, let, and const just like JavaScript.

6. Which symbol is used to specify a variable's type?

  1. :
  2. ;
  3. =
  4. #

Answer: :

A colon (:) is used to declare the data type of a variable.

7. Which of the following is a valid TypeScript type?

  1. number
  2. string
  3. boolean
  4. All of the above

Answer: All of the above

TypeScript includes built-in types such as number, string, and boolean.

8. Which keyword defines an interface in TypeScript?

  1. interface
  2. class
  3. type
  4. struct

Answer: interface

The interface keyword defines the structure of an object.

9. Which keyword is used to create a class in TypeScript?

  1. class
  2. object
  3. struct
  4. define

Answer: class

The class keyword creates a class in TypeScript.

10. Which TypeScript feature helps detect errors during development?

  1. Static Type Checking
  2. DOM
  3. Bootstrap
  4. CSS Modules

Answer: Static Type Checking

Static typing helps catch errors before the code runs.

11. Which keyword is used to create a custom type in TypeScript?

  1. type
  2. interface
  3. class
  4. define

Answer: type

The 'type' keyword creates type aliases in TypeScript.

12. Which TypeScript type can hold any kind of value?

  1. any
  2. mixed
  3. unknown
  4. object

Answer: any

The 'any' type disables type checking for a variable.

13. Which type is safer than 'any' because it requires type checking before use?

  1. unknown
  2. object
  3. dynamic
  4. void

Answer: unknown

The 'unknown' type requires type narrowing before operations.

14. Which keyword is used to inherit a class in TypeScript?

  1. extends
  2. inherits
  3. implements
  4. super

Answer: extends

The 'extends' keyword is used for class inheritance.

15. Which keyword is used to implement an interface?

  1. implements
  2. extends
  3. interface
  4. inherit

Answer: implements

Classes use the 'implements' keyword to implement interfaces.

16. Which type represents a function that returns no value?

  1. void
  2. null
  3. undefined
  4. never

Answer: void

The 'void' type indicates that a function does not return a value.

17. Which symbol is used for optional properties in TypeScript?

  1. ?
  2. !
  3. *
  4. &

Answer: ?

A question mark (?) marks a property as optional.

18. Which TypeScript feature allows one class to reuse another class's properties and methods?

  1. Inheritance
  2. Encapsulation
  3. Abstraction
  4. Polymorphism

Answer: Inheritance

Inheritance enables one class to reuse another class's functionality.

19. Which file is commonly used to configure TypeScript projects?

  1. tsconfig.json
  2. package.json
  3. config.ts
  4. typescript.json

Answer: tsconfig.json

The tsconfig.json file contains TypeScript compiler options.

20. What is the main advantage of using TypeScript?

  1. Static type checking
  2. Faster internet connection
  3. Smaller HTML files
  4. Automatic CSS generation

Answer: Static type checking

TypeScript catches many errors during development through static type checking.

Take the timed quiz