TypeScript: Angular2JS is written in Typescript. Its a superset of javascript. It has a few additional rules as below:
1)myVar = "astring";
myVar = 23; (now assigned to an integer) allowed in javascript.
However, this isnt allowed in Typescript to change the type of the variable.
2)Unlike in javascript, in Typescript, we could declare the type o the variable as below. Its optional
Ex: Types are :
- string.Ex: myVar:string="hello" (or) myVar="hello"
- number. Ex: myVar:number=21 (or) myVar=21
- boolean. Ex: myVar:boolean=true (or) myVar=true
- arrays. Ex: myVar:number[]
- any type as in. Ex: myVar: any ; myVar=50.
- classes. Ex: myVar:<<class-name>>=new <<class-name>>()// as in java
- Ex: Class definition:
{
speed:number;
speed:number;
constructor(mph:number)
{
this.speed = mph;
}
}
- Class instance:
--------------------------------------------------------------------------------------------------------------
No comments:
Post a Comment