As we know that both Typescript and JavaScript are the programming language usually used at client end for processing the server request and rendering data on UI. However, both are scripting language but Typescript supports some additional features than Javascript due to which we can state it as the superset of Javascript.
The following are the important differences between TypeScript and JavaScript.
Sr. No. | Key | TypeScript | JavaScript |
---|---|---|---|
1 | Type | In contrast of type we can say that Typescript is a heavy weight and strongly typed object oriented compile language which is developed by Microsoft. | Javascript on other hand is a light weight interpreted language and is introduced by Netscape. |
2 | Internal implementation | Internal implementation of Typescriipt does not allow it to be used at server side.It can only be used at client side. | On other hand Javascript can be used both at client side and server side. |
3 | Data binding | For binding the data at code level Typescript uses concepts like types and interfaces to describe data being used. | No such concepts has been introduced in Javascript. |
4 | Compilation | Code written in Typescript first need to get compiled and then converted to Javascript this process of conversion is known as Trans-piled. | On other hand no compilation is needed in case of Javascript. |
5 | Modular programming | Typescript gives support for modules hence allows the modular programming. | Javascript does not support modules and hence do not allow the modular programming. |
6 | Optional parameter in function | Any number of optional parameters are allowed in function code written in typescript. | On other hand JavaScript does not support optional parameter function. |
Example of Typescript vs JavaScript
JavaTester.js
<script type="text/javascript"> document.write("Hello World"); </script>
Output
Hello World
Example
JavaTester.ts
var hello: string = "Hello"; var world: string = "World"; console.log(hello + " from " + world);
Output
Hello from World