core typescript Flashcards

1
Q

What is TypeScript?

A

TypeScript is a strongly typed programming language that builds on JavaScript by adding optional static typing and other features. It’s developed by Microsoft and compiles to plain JavaScript.

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

What is the primary advantage of TypeScript over JavaScript?

A

TypeScript provides static type checking at compile time, catching potential errors before runtime and providing better tooling support, code completion, and refactoring capabilities.

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

What happens to TypeScript code during production deployment?

A

TypeScript code is transpiled into JavaScript, meaning all type information is removed and the resulting code can run in any environment that supports JavaScript.

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

How does TypeScript enhance code maintenance in large applications?

A

TypeScript’s type system makes code more self-documenting, enables better IDE support, and makes refactoring safer by catching type-related errors during development.

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

What is type inference in TypeScript?

A

Type inference is TypeScript’s ability to automatically determine types of variables based on their usage and initialization, reducing the need for explicit type annotations.

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

What’s the relationship between TypeScript and ECMAScript?

A

TypeScript is a superset of ECMAScript (JavaScript), meaning it supports all JavaScript features while adding its own capabilities like static typing.

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

How does TypeScript support object-oriented programming?

A

TypeScript adds first-class OOP features to JavaScript including classes, interfaces, access modifiers, and generics.

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

What are declaration files (.d.ts) in TypeScript?

A

Declaration files provide type information for existing JavaScript libraries, allowing TypeScript to understand and provide type checking for external JavaScript code.

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

What is the “strict” compiler option in TypeScript?

A

The strict option enables a set of strict type checking options that enforce more rigorous type safety rules, helping catch more potential errors.

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

What are the main benefits of using TypeScript in a team environment?

A

TypeScript improves collaboration through better code documentation, type definitions that serve as contracts between components, and earlier error detection.

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

How do you declare a variable with an explicit type in TypeScript?

A

let name: string = “John”;
let age: number = 25;

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

What is the syntax for defining an interface?

A

interface User {
id: number;
name: string;
email?: string; // Optional property
}

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

How do you define a function with type annotations?

A

function add(x: number, y: number): number {
return x + y;
}

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

How do you define an enum in TypeScript?

A

enum Direction {
Up = “UP”,
Down = “DOWN”,
Left = “LEFT”,
Right = “RIGHT”
}

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

How do you define a type alias?

A

type Point = {
x: number;
y: number;
};

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

How do you implement an interface in a class?

A

interface Animal {
name: string;
makeSound(): void;
}
class Dog implements Animal {
name: string;
constructor(name: string) {
this.name = name;
}
makeSound() {
console.log(“Woof!”);
}
}

17
Q

What’s the syntax for intersection types?

A

type Employee = Person & {
employeeId: number;
role: string;
};

18
Q

What’s the syntax for defining tuple types?

A

interface Calculator {
add(x: number, y: number): number;
subtract(x: number, y: number): number;
}