Home / Tech / JavaScript vs TypeScript

JavaScript vs TypeScript

JavaScript vs TypeScript

JavaScript is the world’s most popular scripting language for the web. It’s all the rage, everybody knows it, and 96% of the world’s websites use it or some JS-based tech in their infrastructure. However, there is the young, promising, TypeScript, claiming it is the “JavaScript that scales”. As a result, the JavaScript vs TypeScript dilemma has been on every developer’s mind since TypeScript came into our lives. Today, we will try and put that dilemma to rest.

 

But, before we do that, let’s look a bit into both techs and try and see what each is about. Hopefully, by the end of this article, you will know which of the two is best for you.

 

JavaScript

Let’s start with Javascript or vanilla JS. JavaScript a is multi-purpose language, so it works well with both frontend and backend development using for example NodeJS. It is also cross-platform, so it can be used for web development as well as mobile development. Finally, it is an object-oriented language – or OOP – which means that it supports interactive elements, like embedding videos, creating comment sections, adding animations etc. 

 

But, we also know other programming languages that do these things. So, why is JavaScript so popular?

 

JavasScript – the fast, easy and popular option

Programming languages are either compiled – Java for example – or interpreted. Developers using a compiled language have to manually write a “build” that runs and checks the entire code before it is deployed. This makes the chances of buggy code less likely, but the more code you have, the more time consuming it is. Plus, every time there is a change, the developer rewrites the build and starts the whole process again.

JavaScript is an interpreted language meaning that each function is executed by running the code line by line. Because it skips the “build” step, deployment is much faster and fixes and updates are instant. But the downside is that one single error will stop the entire code from rendering. 

 

Nevertheless, all modern browsers support JavaScript and have some sort of debugging tool that allows developers to track errors in the code. But be careful, each browser reads JS differently, so before deploying any code, test it on different platforms.

 

 

Moreover, since each company uses a different stack, working well with other languages is a must. Luckily, JavaScript is a real team player and has no issue communicating with other tech stacks. Just checking different examples like Reddit, Spotify and eBay we see how versatile and adaptable JS is.

 

Is JavaScript really that easy?

The answer is both yes and no. JavaScript is very popular with many experienced developers because it’s simple and easy to learn, use, implement, and deploy. However, if you are a nascent developer, things are a bit more complicated than that. 

 

Even though JS has a low entry barrier and is excellent for small projects, large projects will be an issue. Mostly because writing code in pure JS is time-consuming and prone to errors. This means that running the code will be slow and fixing each bug will add more time to the development process.

 

But, because of its popularity, JavaScript benefits from an incredibly large community and a lot of attention from giant tech companies. Both the community and these companies help create literally hundreds of JS-based tools for different purposes. A famous example is ReactJS, the framework created by Facebook. This also brings us to our second topic of the day, TypeScript.

 

TypeScript

TypeScript is a superset of JavaScript created by Microsoft in order to simplify and enhance JavaScript’s capabilities. In other words, TypeScript is a JavaScript programming language that includes all of JS’s functions – including all JS frameworks and libraries – and adds a few extras on top of that. TS runs in the TypeScript compiler, which as the name suggests, compiles any TypeScript code into “evolved’ vanilla JS code. So at the end of the day, whatever you write in TS, once saved, will become a .js file.

 

The keyword above is “compile”. As mentioned, JS is an interpreted language, so it runs the code line by line and allows fast fixes and changes once an issue is spotted. But this creates an issue because every change may affect many other files you didn’t even think of.

 

TS, on the other hand, is a compiled language, so before the code is deployed, the compiler checks it for errors and alerts the developer. Basically, the compiler does the “build” step for the developer automatically every time there is a change, saving a lot of time.

 

Data validation with TypeScript 

JS is not a strong-type language, which means that developers have to specify different data types in the code manually. This is time-consuming and it risks human-errors as developers might assign the wrong value to the wrong data-type. 

 

 

TypeScript automatically detects and assigns data-types, so it intuitively knows if a piece of data is a number or a string. This reduces development time and eliminates human error.

 

The same function is also useful in bug checks. As you might know, ensuring your JS code is bug-free is a three-step process – automated tests, manual self-checks, code reviews from other developers. That is ok for small and simple applications. But, for companies the size of Microsoft, Facebook, or Google, imagine the hundreds of thousands of lines of code that need checking. 

 

Since TypeScript automatically checks the code, it actually removes the “self-check” step in the bug-hunt, reducing development time significantly. Not to mention that it is more reliable as it is a machine checking the code, not a developer who know the code by heart. However, we still strongly recommend you run automated tests and have other developers review the code before deploying it to production. Don’t get lazy now.

 

Conclusion

Hopefully, now you understand why JavaScript is so beloved. JS is simply an amazing programming language with great capabilities. And the tools and frameworks built based on JS are extremely useful. Moreover, with a community as big as the one behind JavaScript, you will find support easy no matter your problem. 

 

TypeScript is simply a better, more evolved way of writing JavaScript code, and supports all JS-based frameworks, and JS libraries, with extra functions on top. This makes coding a lot easier and faster and really, it does make JavaScript scalable.

 

 

So in the end, whether you go with vanilla JS or use any JS-based tools, TypeScript included, it’s strictly your choice. But one thing we are sure of, TypeScript and JavaScript tools in general make life so much easier.

Source link

Check Also

Robots Everywhere

This is Robots Everywhere — a show where we chronicle the slow but steady takeover ...

Leave a Comment:

Your email address will not be published. Required fields are marked *