Javatpoint Logo
Javatpoint Logo

Difference between JavaScript and TypeScript

JavaScript

JavaScript is the most popular programming language of HTML and the Web. JavaScript is an object-based scripting language which is lightweight and cross-platform. JavaScript is used to create client-side dynamic pages. It was developed by Netscape in 1995.

The programs in JavaScript language are called scripts. They can be written in HTML pages and executed automatically as the page loads. Scripts are provided and executed as plain text. They don't need special preparation or compilation to run.

TypeScript:

TypeScript is an open-source pure object-oriented programing language. It is a strongly typed superset of JavaScript that compiles to plain JavaScript. TypeScript is developed and maintained by Microsoft under Apache 2 license. It was developed by Anders Hejlsberg in the month of 1st October 2012.

It is not directly run on the browser. It needs a compiler to compile and generate in JavaScript file. TypeScript source file is in ".ts" extension. We can use any valid ".js" file by renaming it to ".ts" file. TypeScript is the ES6 version of JavaScript with some additional features.

JavaScript vs TypeScripts

JavaScript Vs TypeScript

SN JavaScript TypeScript
1. It doesn't support strongly typed or static typing. It supports strongly typed or static typing feature.
2. It was developed by Netscape in 1995. It was developed by Anders Hejlsberg in 2012.
3. JavaScript source file is in ".js" extension. TypeScript source file is in ".ts" extension.
4. It is directly run on the browser. It is not directly run on the browser.
5. It is just a scripting language. It supports object-oriented programming concept like classes, interfaces, inheritance, generics, etc.
6. It doesn't support optional parameters. It supports optional parameters.
7. It is interpreted language that's why it highlighted the errors at runtime. It compiles the code and highlighted errors during the development time.
8. JavaScript doesn't support modules. TypeScript gives support for modules.
9. In this, number, string are the objects. In this, number, string are the interface.
10. JavaScript doesn't support generics. TypeScript supports generics.
11. Example:
<script>
function addNumbers(a, b) {  
    return a + b;  
}  
var sum = addNumbers(15, 25);  
document.write('Sum of the numbers is: ' + sum); 
</script>
Example:
function addNumbers(a, b) {  
    return a + b;  
}  
var sum = addNumbers(15, 25);  
console.log('Sum of the numbers is: ' + sum);




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


B.Tech / MCA