Typescript Flashcards

1
Q

var, let, const

A

var is function scoped
let & const is block scoped

var width:number = 100;
let height:number = 200;
const key:string = ‘abc123’;

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

scope of var

A

function

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

scope of let

A

block scope

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

scope of const

A

block scope

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

Basic types / Non-Basic-types

A
boolean
number
string
numer[] or Array
enum
---------
any
never
void
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

initialize an enum

A

Zero-Index

enum Color {Red, Green, Blue};
let c: Color = Color.Green;

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

initialize an Array

A

let aArray: number[] = [1, 2, 3];

let aGenericArray: Array = [4,5,6];

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

never

A

never is used when a function never returns. e.g. it’s in a loop or always throws an exception.

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

Modifier

A

public
protected
private
readonly

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

Duck Typing

A

Compiler kann den Type selbst ableiten

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

Fat Arrow Function

A

(param1, param2, …, paramN) => expression

let sum = (x: number, y: number): number => {
    return x + y;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Generic example

A

interface Identity { id: string; }

class Movie implements Identity {
  id: string;
}
function getAsync(arg: T): Promise {
  return fetch(`/api/${arg.id}`)
    .then((response: Response) => >response.json());
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Diamond Operator

A

<>

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