Intro
You've Definitely heard about both, JavaScript and TypeScript if you're in the loop.
You haven't?
So, if you haven't heard about them. let me give you a quick briefing.
JavaScript
JavaScript is used for developing websites and desktop apps. It is used to improve the UI and add interactivity to the app.
The code below displays an alert saying "Hello, World!" in JS.
alert("Hello, World!");
JavaScript Libraries A JavaScript library is a library of pre-written JavaScript code that allows for easier development of JavaScript-based applications.
Popular JS Libraries:
TypeScript
TypeScript is developed and maintained by Microsoft. It is a strict syntactical superset of JavaScript and adds optional static typing to the language. It is designed for the development of large applications and transpiles to JavaScript.
The code below displays an alert saying "Hello, World!" in TS.
let message: string = 'Hello, World!';
console.log(message);
What is the difference between them?
When JavaScript was developed, the JavaScript development team introduced JavaScript as a client-side programming language. But as people were using JavaScript, developers also realized that JavaScript could be used as a server-side programming language. However, as JavaScript was growing, JavaScript code became complex and heavy. Because of this, JavaScript wasn’t even able to fulfill the requirement of an Object-Oriented Programming language. This prevented JavaScript from succeeding at the enterprise level as a server-side technology. So TypeScript was created by the development team to bridge this gap.
-TypeScript is known as an Object-oriented programming language whereas JavaScript is a scripting language.
TypeScript has a feature known as Static typing but JavaScript does not support this feature.
TypeScript supports Interfaces but JavaScript does not.
Advantages of using TypeScript over JavaScript
- TypeScript supports static/strong typing. This means that type correctness can be checked at compile time. This feature is not available in JavaScript.
- TypeScript always points out the compilation errors at the time of development (pre-compilation). Because of this getting runtime errors is less likely, whereas JavaScript is an interpreted language.
- TypeScript is nothing but JavaScript and some additional features i.e. ES6 features. It may not be supported in your target browser but the TypeScript compiler can compile the .ts files into ES3, ES4, and ES5 also.
Disadvantages of using TypeScript over JavaScript
- Generally, TypeScript takes time to compile the code.
Reading this, you may feel that TypeScript is obviously better than JavaScript, but that is not the case. TypeScript is not a replacement for JavaScript and is not suitable for all types of projects. JavaScript is still the most favorite client-side scripting language. Since JavaScript is directly run on the browser, it's easier to run, refresh and debug small code chunks.
The Final Verdict
Reading this, you should decide for yourself, based on what kind of project you're working on!
Hope you've had a good read! Thanks for visiting, and make sure to see my other blogs as well!