Posts

Typescript Introduction

Typescript is a super set of java script, when we compile (transpile) Typescript code it generates java script code. In sort, Typescript is a language which generates java script when compiled. all the java script code is a valid Typescript code (i.e. we can write java script code inside type script file). Now question comes in our mind, why we need typescript? because it's a typed language as we know that java script is not typed language, In java script, data type of a variable inferred by compiler automatically based on value assigned to it. for example : var name ="nds";// name is string       name =40; // here name is number       name =true; //here name is boolean. In Typescript, we can declare type of a variable so, it will accept value only the declared type. apart from this, some more differences exists between typescript and java script. some features of Typescript's included in the newer version of Java script (ES-6) as well.

Data types in Typescript

Data types in Typescript: Syntax to declare a variable :   var/let varName : datatype;  we can also assign value at the time of variable declaration.(see below examples). We can define datatype of a variable, from below mentioned types: Number : // Number let   num : number ; console . log ( num ); // undefined num = 33 ; console . log ( num );  //33 console . log ( "What if, we will try to assign any other type of value to num" ); // num="sss"; // Error :Type '"sss"' is not assignable to type 'number'. // console.log(num); Boolean: let   isBoolean :   boolean = true ;  // isBoolean will accept only 'true' and 'false' values. console . log ( isBoolean ); String: all java script code is valid Typescript code so, we can also use java scrip...