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
- class Greeter {
- greeting: string;
- constructor(message: string) {
- this.greeting = message;
- }
- greet() {
- return "Hello, " + this.greeting;
- }
- }
- JavaScript: var Greeter = (function() {
- function Greeter(message) {
- this.greeting = message;
- }
- Greeter.prototype.greet = function() {
- return "Hello, " + this.greeting;
- };
- return Greeter;
- })();