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. It is used to create client-side dynamic pages. The programs in JavaScript language are called scripts. The scripts are written in HTML pages and executed automatically as the page loads. It is provided and executed as plain text and does not need special preparation or compilation to run.
History of JavaScript
Netscape Communications Corporation programmer Brendan Eich developed JavaScript. It was introduced in September 1995, which was initially called Mocha. However, after gaining popularity as the best scripting tool, it was renamed as JavaScript to reflect Netscape's support of Java within its browser. In November 1996, Netscape submitted JavaScript to ECMA (European Computer Manufacturers Association). The current version of JavaScript is ECMAScript 2018, which was released in June 2018./p>
TypeScript
TypeScript is an open-source pure object-oriented programing language. It is a strongly typed superset of JavaScript which compiles to plain JavaScript. TypeScript is developed and maintained by Microsoft under the Apache 2 license. 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.
History of TypeScript
Anders Hejlsberg developed TypeScript. It was first introduced for the public in the month of 1st October 2012. After two years of internal development at Microsoft, the new version of TypeScript 0.9 was released in 2013. The current version of TypeScript is TypeScript 3.4.5 which was released on 24 April 2019.
Advantage of TypeScript over JavaScript
- TypeScript always highlights errors at compilation time during the time of development, whereas JavaScript points out errors at the runtime.
- TypeScript supports strongly typed or static typing, whereas this is not in JavaScript.
- TypeScript runs on any browser or JavaScript engine.
- Great tooling supports with IntelliSense which provides active hints as the code is added.
- It has a namespace concept by defining a module.
Disadvantage of TypeScript over JavaScript
- TypeScript takes a long time to compile the code.
- TypeScript does not support abstract classes.
- If we run the TypeScript application in the browser, a compilation step is required to transform TypeScript into JavaScript.
TypeScript Vs. JavaScript
SN | JavaScript | TypeScript |
---|---|---|
1. | It doesn't support strongly typed or static typing. | It supports strongly typed or static typing feature. |
2. | Netscape developed it in 1995. | Anders Hejlsberg developed it 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); |
Source : https://www.javatpoint.com/javascript-vs-typescript