Typescript-101 Flashcards

1
Q

What is the diff b/w let, var & const?

A

Var will create a global variable and it is availabel in Global Object
Let will create a global variable, but does not belong to Global Object
Const will create a global Constant and it is not a property of Global Object

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

What is the advantage of let?

A

With let you can create block level vars

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

What is the advantage of const?

A

const requires intiallization and must not change while time

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

Can we define objects with let

A

Yes

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

Ca we define html templates with let

A

Yes A good way to do that

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

How can you define template literals with let?

A
let obj = {
name : "kjskj
}"

let templateStr = “Name is” + $(obj.name)

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

What is arrow function?

A

Arrow function is one way of writing inline function, like

var sum = (a,b) => { return a+b;}

var sum = (a,b) => a+b;

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

Does Arrow function retains the Lexical scope of this?

A

YEs

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

Write code for a class and constructor?

A

Class Person {
constructor(name) { // need not define the as var or let
this.name = name;
}

}

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

Do you add access modifer or return type in function or construtors?

A

Nope straight to name

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

How can you extend the class ?

A

Using keyword extends and use super where required

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

How can we create an obj of a class?

A

let obj = new Employee(“sdfsfdee”);

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

What is Object.create

A

To do prototypical inheritance without using constructor function

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

What is the public access modifier?

A

Use export

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

What is import do?

A

To import any exported entity

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

How can you import everthing ?

A

import * as item from “./mod.js”

17
Q

Give one example of how the typesscript code looks in JS form?

A

class Greeter {
greeting : string;
constructor(message: string){
this.greeting: message;

}

greet(){

return “Greet”

}

let greeter = new Greeter(“Greeter”);

}

The above looks below in JS:

var Greeter = (function(){
      function Greeter(message){
               this.greeting = message;

}

Greeter.prototype.greet = function(){
return “Greet”;

}

return Greeter; // So i JS you can return the obj in the class itself as we do in JAVA

}());

18
Q

How do you define a String type in TS?

A

message: string;

19
Q

Do we require to specify the function keyword to start a function?

A

Need not

20
Q

How many Primitive types we have in TS?

A

string, Number, Boolean, undefined, null

21
Q

What all format des Number supports?

A

Float and int, also it supports Hexadecimal, Octal, decimal, binary

22
Q

How do you define the variable , variabetype , variablename & variablevalue?

A

let fName: string = ““myname””;

23
Q

What is the diff b/w null & undefined?

A

undefined means the value has not been defined, null means it has defined the object & that object is null.

24
Q

Do we have Array, Enum, Any & Void in TS

A

Yes we have

25
Q

How do you define an array

A

var listnum:number[] = [20,40];

26
Q

How do you make one Any type var ?

A

let me; Or var me;

27
Q

How do you define enums?

A
enum Cards{DIAMOND, SPADE};
var c = Cards.DIAMOND;
c= 1;// Cards.DIAMOND;
28
Q

How can I define a function with a function keyword?

A
function getData(mesaage): void{
//do some
}
29
Q

How do define an interface?

A

interface myInterface {
greetUser(message: string): void;
}

30
Q

How can we implement and interface?

A
class implClass implements myInterface {
  greetUser(msg: string){

return “name”;
}

}

31
Q

How will you aceess the methods of a class?

A
function(greet: GreeterClass){
     greet.greetUser("Hello");
}
32
Q

What is the default access modifer?

A

public

33
Q

Which keyword helps in instantiating a class?

A

new

34
Q

How can you define an anonymous function?

A

let myFunct = function(message: string) {return message};

35
Q

How can we pass a default value to a function argument?

A

function me(message: string =”hello”){

}