Saturday, June 20, 2020

JavaScript TypeScript

TypeScript


JavaScript

JavaScript was developed initially as a client-side programing language. Programmers realized that JavaScript can be used as a server-side programming language too. JavaScript had a lot of potentials, but still, it lacks the ability to maintain large and complex programs. JavaScript lacks various structuring mechanisms like static typing, classes, modules, and interfaces.

TypeScript


TypeScript is an open-source programming language built over JavaScript and maintained by Microsoft. TypeScript is a typed superset of JavaScript that is ultimately compiled into regular JavaScript. It allows developers to create scalable and maintainable JavaScript development. It can be run on any browser, host, or OS.

typescript javascript


TypeScript opted for the same JavaScript syntax and semantics. We can use existing JavaScript code, integrate popular JavaScript libraries, and call TypeScript code from JavaScript. 


typescript


TypeScript code is compiled into a clean, simple JavaScript code that can be executed on any browser, in Node.js, or in any JavaScript engine supporting ECMAScript 3 (or newer). The browsers do not understand the Typescript(.ts extension) directly, so first this code is compiled and transformed into JavaScript (.js Extension). This code is known as trans-piled code. This code is eventually run by the browsers.


Features of TypeScript


TypeScript has following features
 
  • TypeScript supports standard JavaScript code with static typing
  • Zero cost: Static types completely disappear at run-time
  • TypeScript supports encapsulation through classes, modules, and interfaces
  • TypeScript supports constructors, properties, and functions (public, private)
  • TypeScript supports enums, lambdas and generics support
  • Intellisense and syntax checking can be incorporated with TypeScript
  • Designed for large scale development
  • TypeScript allows the support for optional parameter function that is not supported by JavaScript.


TypeScript code is compiled; it means the errors can be detected at the development phase, it reduces the chances of the run-time errors significantly in comparison to the JavaScript as it is an interpreted language.

TypeScript is strongly-typed (known as static typing), it allows for checking type correctness at compile time. This feature is absent in JavaScript. TypeScript is nothing but JavaScript with some improvements over ES6 JavaScript features. It may not be supported by few browsers but the TypeScript compiler can compile the .ts files into ES3,ES4 and ES5 also.