Difference between TypeScript and JavaScript

JavascriptType ScriptObject Oriented Programming

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.KeyTypeScriptJavaScript
1TypeIn 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.
2Internal implementationInternal 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.
3Data bindingFor 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.
4CompilationCode 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.
5Modular programmingTypescript gives support for modules hence allows the modular programming.Javascript does not support modules and hence do not allow the modular programming.
6Optional parameter in functionAny 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
raja
Published on 18-Sep-2019 17:15:14
Advertisements