*Hey guys, *
lately, I watched a video about TypeScript so my curiosity got me to search for the difference between TypeScript and JavaScript.
Many sources talk about JavaScript and TypeScript looks very similar, but there's one crucial distinction.
The key difference between JavaScript and TypeScript is that JavaScript lacks a type system. In JavaScript, variables can haphazardly change the form, while TypeScript in strict mode forbids this.
For example, Variables in JavaScript
let x = 1
let y = "text"
y = 123 // allowed in JavaScript
Variables in TypeScript
let x: number = 1
let y: string = "text"
y = 123 // not allowed in TypeScript
The difference in syntax is minor.
Difference between TypeScript and JavaScript
- TypeScript is known as an Object-oriented programming language whereas JavaScript is a prototype-based 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 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 supports static/strong typing. This means that type correctness can be checked at compile time. This feature is not available in JavaScript.
-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.
So let's share our knowledge and tell me what you learned today.
Here are my social links if you would like to follow.
Github: https://github.com/EsraaNasr92/
Twitter / X: https://twitter.com/Esraa_nasr92
Instgram: https://www.instagram.com/_esraaanasr/
Top comments (1)
It's worth mentioning also that compiled TypeScript package is bigger than you'd expect.