What is TypeScript & Why You Use It?

TypeScript is a JavaScript superset. It is not a new language. It takes JavaScript and adds new features and advantages to it. It makes writing JavaScript code easier and more powerful. It has one disadvantage: It cannot be executed by JavaScript environments like the browser. Also, Node.js can not execute TS. Now, how will this work. So, typescript is also a tool. You use it to compile your TS code to JS, which can be executed by JS environments.

Screenshot 2022-10-17 at 1.26.04 PM.png

Now, TS adds types to JS. So, it will prevent runtime errors. It also solves logical erros like:

Screenshot 2022-10-17 at 1.41.20 PM.png

Now, there are ways to do this in JS but it would be better if there were ways to do this during dev.

That is why we use typescript.

Installing and using TS:

To install:

In the github repo find the 1-basic-proj in which there is a html and a JS file to add 2 numbers:

index.html:

Screenshot 2022-10-17 at 1.45.30 PM.png

js-only.js:

Screenshot 2022-10-17 at 1.45.45 PM.png

Output:

Screenshot 2022-10-17 at 1.46.13 PM.png