+ 2

What is major difference between javascript and typescript?

2nd Apr 2021, 9:23 AM
Arqum Farooq
Arqum Farooq - avatar
2 Respostas
+ 7
TypeScript adds a compilation step (comes before run time) and types which are checked during development to help you fight potential bugs before your code gets to run time. You'll hear these two descriptions being thrown around quite often: 1. TypeScript is a superset of JavaScript. 2. TypeScript is just JavaScript with types. These statements are a bit clichéd but they are valid. For 1: This means that TS adds a layer on top of JS to provide extra features, but at the end of the day, once the code reaches its runtime (not compile time), it all becomes JS. All JS is valid TS when it comes to syntax. This doesn't mean that the TS compiler will necessarily be happy with any given piece of JS code. Essentially, TypeScript's extra features try to help you out during development, but at run time, it's JS that gets executed. For 2: Types refers to a key feature that TS gives you. All values have a type. E.g. a variable with a type of string can't be reassigned to hold a non-string value.
2nd Apr 2021, 9:51 AM
CamelBeatsSnake
CamelBeatsSnake - avatar
2nd Apr 2021, 9:41 AM
Ipang