Differences Between JavaScript And TypeScript

Javascript

Typescript

It is a scripting language.

It is an object oriented programming language(not pure).

There is no static typing. ex: var num.

Here it is static typing (We can declare a variable in multiple ways). ex: var num : number.

It doesn't have interfaces .

It has interfaces.

It has no optional parameter feature.

It has optional parameter feature.

It has no Rest Parameter feature.

No generics are supported

It has Rest Parameter feature.

Supports generics.

No modules support.

Number, string etc. are the objects.

Supports Modules .

Number, string etc. are the interfaces.

Example code for TypeScript & JavaScript is given below.

TypeScript 
  1. class Greeter {  
  2.     greeting: string;  
  3.     constructor(message: string) {  
  4.         this.greeting = message;  
  5.     }  
  6.     greet() {  
  7.         return "Hello, " + this.greeting;  
  8.     }  
  9. }  
  10. JavaScript: var Greeter = (function() {  
  11.     function Greeter(message) {  
  12.         this.greeting = message;  
  13.     }  
  14.     Greeter.prototype.greet = function() {  
  15.         return "Hello, " + this.greeting;  
  16.     };  
  17.     return Greeter;  
  18. })();
Ebook Download
View all
Test
Read by 16 people
Download Now!
Learn
View all