← back

Why I Prefer Type-Script more than JavaScript …?

Cover Image for Why I Prefer Type-Script more than JavaScript …?

So a Little intro to Typescript, It was developed by Microsoft as a opensource project and its now also maintained by Microsoft.

So Basically in a nutshell Typescript is the super set of JavaScript meaning any valid JavaScript code is a valid Type-Script Code.

If you have experience with JS you know that the data type is completely dynamic, to give you a example, I declare arr as a const , and try to apply arr.map() function, This is a error because arr is not a array to map through and we’ll get to know this error during run (JS doesn’t need any compiling we can directly run / interpret it in Browser) time which is more frustrating for a developer

Now, lets come to typescript you have to mention the datatype of arr which is a string and if you try to apply arr.map() the text editor will scream at you saying that you cannot loop though a string….

TypeScript is strictly better than JavaScript. Some of the advantages are below,

  • Static types prevent an entire category of errors. And they prevent the errors before you even save the code to disk. The sooner you detect an error, the cheaper it is to fix in developers point of view.

  • It forces you to write clean code, so if you forget your code after a couple months you can just see what you have written and what does this do in just couple minutes..

  • If you are building a large Systems, Its Oriented and complex systems is no longer a nightmare.

Compilation

A main dIffrence between JavaScript and TypeScript is compilation. There is no need to build JS code. In the browser, it is interpreted and executed. TypeScript code, on the other hand, must be converted into standard JS and then compiled. It may seems that you might be wasting time, but you are actually saving time. Compiling the code takes a few extra seconds, but it saves time when you are testing your application.

After everything is said and done, both Typescript and JavaScript have their own set of limitations and features. JS is a dynamic and lightweight coding language designed to improve HTML web pages. It is not, however, a full-fledged scripting language. JS is an interpreted programming language that runs in the context of a web browser.

Typescript is compiled to JS, which can be used in any JS code; as a result, Typescript has more advantages, making it more significant and popular.

Final Notes:

The community for Typescript is not big as JS

Use TS always whenever you are making a big application with complicated Data and interacting with various Databases

You can get more accurate Auto completions in your text editor as the transpiler knows what data type it is

Start Migrating your codebases to TS, its easy just renaming the file extensions to .ts` Of course, JavaScript code won’t become a strict TypeScript automatically. It still takes some time and effort to convert.But its so much worth it to make it.

Just use Ts, You’ll thank me later xD.