Typescript Flashcards

1
Q

What is TypeScript?

A

TypeScript is a superset of JavaScript that adds static typing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

True or False: TypeScript can compile to plain JavaScript.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Fill in the blank: TypeScript uses ____ to define the type of a variable.

A

annotations

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What command is used to install TypeScript globally?

A

npm install -g typescript

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the purpose of the ‘tsconfig.json’ file?

A

It configures the TypeScript compiler options for a project.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Multiple Choice: Which of the following is a primitive type in TypeScript? A) string B) Array C) Object

A

A) string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does the ‘any’ type in TypeScript represent?

A

It represents any value and disables type checking.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

True or False: TypeScript supports interfaces.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is an interface in TypeScript?

A

An interface defines the structure of an object, specifying properties and methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Fill in the blank: In TypeScript, ____ can be used to define a function signature.

A

function types

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the difference between ‘interface’ and ‘type’ in TypeScript?

A

‘interface’ can be extended while ‘type’ cannot.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Multiple Choice: Which keyword is used to create a class in TypeScript? A) create B) class C) function

A

B) class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

True or False: TypeScript supports decorators.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a tuple in TypeScript?

A

A tuple is an array with a fixed number of elements with known types.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Fill in the blank: TypeScript’s ____ feature allows for optional properties in an object.

A

optional chaining

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the use of the ‘readonly’ modifier in TypeScript?

A

It makes a property immutable after its initial assignment.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Multiple Choice: What symbol is used for defining a union type in TypeScript? A) & B) | C) ?

A

B) |

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

True or False: TypeScript can infer types automatically.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is a namespace in TypeScript?

A

A namespace is a way to encapsulate related code to avoid name collisions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Fill in the blank: You can use the ____ keyword to define a generic type in TypeScript.

A

generic

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is the purpose of the ‘never’ type in TypeScript?

A

It indicates a value that never occurs, such as in a function that throws an error.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Multiple Choice: Which of the following is NOT a TypeScript built-in type? A) string B) number C) void D) character

A

D) character

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

True or False: TypeScript can be used with React.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What is the purpose of the ‘as’ keyword in TypeScript?

A

It is used for type assertions to tell the compiler to treat a variable as a specified type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

Fill in the blank: TypeScript supports ____ types, which allow defining a variable that can have multiple types.

A

union

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What does the ‘strict’ option in ‘tsconfig.json’ enable?

A

It enables all strict type-checking options.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

Multiple Choice: How do you declare a variable with a specific type in TypeScript? A) var x: number B) let x = number C) x: number

A

A) var x: number

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

True or False: TypeScript allows the use of JavaScript libraries without type definitions.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

What is a type guard in TypeScript?

A

A type guard is a runtime check that ensures a variable is of a specific type.

30
Q

Fill in the blank: The ____ operator is used to spread elements of an array or object.

A

spread

31
Q

What does the ‘unknown’ type represent in TypeScript?

A

It represents any value but requires type checking before performing operations.

32
Q

Multiple Choice: Which of the following is a valid way to define a function in TypeScript? A) function add(a: number, b: number): number B) add(a, b): number C) function add(a, b): void

A

A) function add(a: number, b: number): number

33
Q

True or False: TypeScript can be used for both frontend and backend development.

A

True

34
Q

What is the purpose of ‘declaration files’ in TypeScript?

A

They provide type information about JavaScript libraries.

35
Q

Fill in the blank: You can create a default export in TypeScript using the ____ keyword.

A

export default

36
Q

What does the ‘keyof’ operator do in TypeScript?

A

It creates a union type of all the keys of an object type.

37
Q

Multiple Choice: Which of the following is used to create an interface extending another interface? A) extends B) implements C) inherits

A

A) extends

38
Q

True or False: TypeScript allows for function overloading.

A

True

39
Q

What is the purpose of the ‘this’ parameter in TypeScript methods?

A

It allows you to specify the type of ‘this’ within the method.

40
Q

Fill in the blank: The ____ keyword is used to create a type alias in TypeScript.

A

type

41
Q

What is the purpose of the ‘public’, ‘private’, and ‘protected’ modifiers in TypeScript classes?

A

They control the accessibility of class members.

42
Q

Multiple Choice: Which of the following is a way to define a module in TypeScript? A) module MyModule B) namespace MyModule C) package MyModule

A

B) namespace MyModule

43
Q

True or False: You can use TypeScript with Node.js.

A

True

44
Q

What is type inference in TypeScript?

A

Type inference is the ability of TypeScript to automatically deduce the type of a variable.

45
Q

Fill in the blank: In TypeScript, the ____ operator is used to assert that a variable is of a specific type.

A

as

46
Q

What is the purpose of ‘Promise’ in TypeScript?

A

It represents the eventual completion (or failure) of an asynchronous operation.

47
Q

Multiple Choice: Which of the following is a valid way to create a generic function in TypeScript? A) function identity<T>(arg: T): T B) function identity(arg: T): T C) function identity<T>(arg): T</T></T>

A

A) function identity<T>(arg: T): T</T>

48
Q

True or False: In TypeScript, enums are a way to define named constants.

A

True

49
Q

What is the purpose of the ‘async’ and ‘await’ keywords in TypeScript?

A

They are used to work with asynchronous code more easily.

50
Q

Fill in the blank: TypeScript’s ____ feature allows for destructuring of objects and arrays.

A

destructuring

51
Q

What is a ‘mapped type’ in TypeScript?

A

A mapped type creates a new type by transforming properties of an existing type.

52
Q

Multiple Choice: Which of the following allows you to create a read-only version of an object type? A) Readonly<T> B) Const<T> C) Immutable<T></T></T></T>

A

A) Readonly<T></T>

53
Q

True or False: TypeScript allows for module augmentation.

A

True

54
Q

What is the ‘void’ type used for in TypeScript?

A

It indicates that a function does not return a value.

55
Q

Fill in the blank: In TypeScript, the ____ operator is used for optional chaining.

A

?.

56
Q

What does ‘strictNullChecks’ do in TypeScript?

A

It prevents null and undefined from being assigned to variables of other types.

57
Q

Multiple Choice: How do you define a variable that can be either a string or null in TypeScript? A) string | null B) string & null C) string ?

A

A) string | null

58
Q

True or False: TypeScript can be used to build large-scale applications.

A

True

59
Q

What is the role of ‘type definitions’ in TypeScript?

A

They provide type information for existing JavaScript code.

60
Q

Fill in the blank: A ____ is a function that returns another function in TypeScript.

A

closure

61
Q

What does ‘type assertion’ mean in TypeScript?

A

It tells the compiler to treat a variable as a certain type.

62
Q

Multiple Choice: Which of the following is a correct way to define an interface in TypeScript? A) interface IUser B) type IUser C) class IUser

A

A) interface IUser

63
Q

True or False: TypeScript does not support functional programming techniques.

A

False

64
Q

What is the purpose of the ‘export’ keyword in TypeScript?

A

It allows a module to expose its members for use in other modules.

65
Q

Fill in the blank: The ____ modifier can be used to make a class member static in TypeScript.

A

static

66
Q

What is the difference between ‘let’ and ‘const’ in TypeScript?

A

‘let’ allows reassignment while ‘const’ does not.

67
Q

Multiple Choice: Which of the following is a way to define a type for a function in TypeScript? A) function myFunc: () => void B) myFunc: () => void C) myFunc(): void

A

B) myFunc: () => void

68
Q

True or False: TypeScript allows for the creation of custom types.

A

True

69
Q

What is the purpose of the ‘import’ statement in TypeScript?

A

It allows you to include modules or specific members from other files.

70
Q

Fill in the blank: The ____ operator is used to combine multiple types into one in TypeScript.

A

intersection