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
Fill in the blank: TypeScript supports ____ types, which allow defining a variable that can have multiple types.
union
26
What does the 'strict' option in 'tsconfig.json' enable?
It enables all strict type-checking options.
27
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) var x: number
28
True or False: TypeScript allows the use of JavaScript libraries without type definitions.
True
29
What is a type guard in TypeScript?
A type guard is a runtime check that ensures a variable is of a specific type.
30
Fill in the blank: The ____ operator is used to spread elements of an array or object.
spread
31
What does the 'unknown' type represent in TypeScript?
It represents any value but requires type checking before performing operations.
32
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) function add(a: number, b: number): number
33
True or False: TypeScript can be used for both frontend and backend development.
True
34
What is the purpose of 'declaration files' in TypeScript?
They provide type information about JavaScript libraries.
35
Fill in the blank: You can create a default export in TypeScript using the ____ keyword.
export default
36
What does the 'keyof' operator do in TypeScript?
It creates a union type of all the keys of an object type.
37
Multiple Choice: Which of the following is used to create an interface extending another interface? A) extends B) implements C) inherits
A) extends
38
True or False: TypeScript allows for function overloading.
True
39
What is the purpose of the 'this' parameter in TypeScript methods?
It allows you to specify the type of 'this' within the method.
40
Fill in the blank: The ____ keyword is used to create a type alias in TypeScript.
type
41
What is the purpose of the 'public', 'private', and 'protected' modifiers in TypeScript classes?
They control the accessibility of class members.
42
Multiple Choice: Which of the following is a way to define a module in TypeScript? A) module MyModule B) namespace MyModule C) package MyModule
B) namespace MyModule
43
True or False: You can use TypeScript with Node.js.
True
44
What is type inference in TypeScript?
Type inference is the ability of TypeScript to automatically deduce the type of a variable.
45
Fill in the blank: In TypeScript, the ____ operator is used to assert that a variable is of a specific type.
as
46
What is the purpose of 'Promise' in TypeScript?
It represents the eventual completion (or failure) of an asynchronous operation.
47
Multiple Choice: Which of the following is a valid way to create a generic function in TypeScript? A) function identity(arg: T): T B) function identity(arg: T): T C) function identity(arg): T
A) function identity(arg: T): T
48
True or False: In TypeScript, enums are a way to define named constants.
True
49
What is the purpose of the 'async' and 'await' keywords in TypeScript?
They are used to work with asynchronous code more easily.
50
Fill in the blank: TypeScript's ____ feature allows for destructuring of objects and arrays.
destructuring
51
What is a 'mapped type' in TypeScript?
A mapped type creates a new type by transforming properties of an existing type.
52
Multiple Choice: Which of the following allows you to create a read-only version of an object type? A) Readonly B) Const C) Immutable
A) Readonly
53
True or False: TypeScript allows for module augmentation.
True
54
What is the 'void' type used for in TypeScript?
It indicates that a function does not return a value.
55
Fill in the blank: In TypeScript, the ____ operator is used for optional chaining.
?.
56
What does 'strictNullChecks' do in TypeScript?
It prevents null and undefined from being assigned to variables of other types.
57
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) string | null
58
True or False: TypeScript can be used to build large-scale applications.
True
59
What is the role of 'type definitions' in TypeScript?
They provide type information for existing JavaScript code.
60
Fill in the blank: A ____ is a function that returns another function in TypeScript.
closure
61
What does 'type assertion' mean in TypeScript?
It tells the compiler to treat a variable as a certain type.
62
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) interface IUser
63
True or False: TypeScript does not support functional programming techniques.
False
64
What is the purpose of the 'export' keyword in TypeScript?
It allows a module to expose its members for use in other modules.
65
Fill in the blank: The ____ modifier can be used to make a class member static in TypeScript.
static
66
What is the difference between 'let' and 'const' in TypeScript?
'let' allows reassignment while 'const' does not.
67
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
B) myFunc: () => void
68
True or False: TypeScript allows for the creation of custom types.
True
69
What is the purpose of the 'import' statement in TypeScript?
It allows you to include modules or specific members from other files.
70
Fill in the blank: The ____ operator is used to combine multiple types into one in TypeScript.
intersection