Difference between Javascript and Typescript

(Last Updated On: November 25, 2017)

Difference between Javascript and Typescript:


var myVar = 'hello';
myVar = 10;
// prints 10
let myVar = 'hello';
myVar = 10;
// we get the error here stating
//Type 'number' is not assignable to type 'string'
We dont have a type number only in javascript.Typescript does not have float/double types, everything is considered as type number only (like 10, 11.2, 27.8000).
As types are not supported in javascript, explicit assignments will also be not possible.Explicit assignment is possible
let name:string = 'javadomain';
let price:number = 100000;
We dont have any types like any, and also it even does not maintain the types internally based on the initialization assignmentswe can have the variable with type 'any', then which is allowed to hold any types like string/number etc.
Javascript does not have type tuple object.Tuples can be used to have the mixed type contents in an array.

175 total views, 2 views today

Leave a Reply

Your email address will not be published. Required fields are marked *