JavaScript Vs TypeScript: A Comprehensive Comparison

There were simpler times when all you needed to know was that JavaScript is a client-side programming language and it can change and update both HTML and CSS. In short, JavaScript had the ability to enhance your Web Pages.

JavaScript Vs TypeScript: A Comprehensive Comparison

There were simpler times when all you needed to know was that JavaScript is a client-side programming language and it can change and update both HTML and CSS. In short, JavaScript had the ability to enhance your Web Pages.

Then came, “TypeScript”. It encompasses all of the JavaScript and claimed to be a superset of JavaScript. At first, everyone was skeptical but soon there was an army of developers backing up TypeScript. This was back in 2012 when TypeScript was first made public.

Although TypeScript turned out to be exactly what it claimed to be, JavaScript still reigns supreme. In this article, I will make a comprehensible comparison as to why JavaScript is still in the lead and why TypeScript is gaining popularity with each passing day.

Instead of directly diving into “TS vs JS” or in other terms “Difference between JavaScript and TypeScript”, let’s start with what they are and what makes them unique.

Starting with JavaScript!

What is JavaScript

According to developers at Mozilla:

“JavaScript is a scripting or programming language that allows you to implement complex things on web pages — every time a web page does more than just sit there and display static information for you to look at — displaying timely content updates, interactive maps, animated 2D/3D graphics, scrolling video jukeboxes, etc. — you can bet that JavaScript is probably involved...”

This is one of the most comprehensible definitions out there and it defines perfectly what JavaScript is.

It was Brendan Eich who developed JavaScript while working at Netscape in 1995. According to Brendon, he got the inspiration for JavaScript from Scheme, Self, and Java.

At first, the rise of JavaScript was fairly steady but it was Dynamic Web Applications that gave JavaScript a boost to mainstream development. As the web grew more and more, it became a hub for exciting application. And guess what you needed in order to stand out or at least fit in this new ecosystem… it was JavaScript. Static pages were no longer the norm, the new norm was dynamic web applications created with the help of JavaScript.
According to usage statistics by w3tech, as of 2019, JavaScript is used by 95.2% of all the websites in existence (Which is near ~200 Million active websites, that is a two with eight zeros… 200,000,000)

Key Selling Point Of JavaScript

The most important aspect which influenced such as the wide following is JavaScript’s ability to create interactive web pages with ease.

“Hello World” JavaScript Code Example

<!DOCTYPE html>
<html>
<body>
<p id="JavaScript"></p>
<script>
document.getElementById("JavaScript").innerHTML = "Hello World";
</script>
</body>
</html>

What is Typescript

Let’s start with a definition.

“Microsoft TypeScript is an open-source programming language developed and maintained by Microsoft. It is a strict syntactical superset of JavaScript and adds optional static typing to the language. TypeScript is designed for development of large applications and trans-compiles to JavaScript” ~wikipedia

Read the definition again, you might have missed the most important part. “...designed for development of large application...”

TypeScript is everything JavaScript is not. JavaScript was originally meant for smaller applications. Many complications arise as we continue to scale JavaScript. TypeScript handles all these complications seamlessly and is designed to be scaled.

TypeScript was launched for public use as an open source programming language in 2012. Since then the popularity of TypeScript has been growing steadily as indicated by Google Trends.

The future of TypeScript is somewhat still in debate. While ~50% of developers stand for TypeScript, the other 50% is not so sure. As for why this is the case, I will discuss it shortly.

Key Selling Point

The key feature TypeScript has to offer can excellently be explained in this one sentence:

TypeScript: JavaScript That Scales

Hello World code Example

class Hello {
constructor (public msg: string){
sayHello() {
return "<h2>" + this.msg + "</h2>";
};
var hello = new Hello("Hello World, What do you think of TypeScript? ");
document.body.innerHTML = hello.sayHello();

-----------

<!DOCTYPE html>
<html>
<head><title>TypeScript Hello World | Tutorial Jini </title></head>
<body>
<script src='hello.js'></script>
</body>
</html>

TypeScript vs Javascript

Now that we have established that both JavaScript and TypeScript have a substantial backing from developers, let’s now dive into as to why developers favor either one of these languages.

TypeScript Advantages Over Javascript

Javascript was meant to be a client-side programming language. In time developers realized that JavaScript can also be used as a server-side programming language. But there was a problem. JavaScript would become extremely complex as it scaled. Thus there was a need to bridge this gap and it was done by the introduction of TypeScript.

  • TypeScript is able to point out errors in compilation ever during development.
  • For checking type correctness at compile time, TypeScript has the feature of strongly-typed or static typing.
  • TypeScript is better equipped to handle the server-side.
  • TypeScript to JavaScript: TypeScript code can be converted into JavaScript and thus it can be understood by the browser. It is done with the help of a method called Trans-Piled.
  • JavaScript to TypeScript: Since TypeScript is a superset of JavaScript, JavaScript code IS TypeScript code. It can be converted into TypeScript just by changing the extension of the file from “.js” to “.ts”.
  • Unlike JavaScript, in TypeScript the same code can be run on any browser, device and operating system.
  • TypeScript also supports JavaScript libraries and API documentation.
  • TypeSCript can be extended beyond the standard decorators.

The list can go on and on but these are the major advantages TypeScript has over JavaScript. Now, let’s move on the advantage that Javascript has over TypeScript.

JavaScript Advantages Over TypeScript

When JavaScript was created it was not called JavaScript, it was called Mocha. The Brendan Eich was hired to make a language that could be run in a browser by Netscape, he was supposed to have finished it yesterday (It's a pun). That was how little time he was given to create it. JavaScript is so malleable that it is famously said that “Everything that can be made in JavaScript will eventually be made in JavaScript”. JavaScript is in par with PHP too, with many people speculating that JavaScript is more important and has more influence than PHP. You can check out a detailed comparison between JavaScript and PHP in one of our blogs.

And that is exactly what it did, JavaScript was famously created by Brendan Eich in just 10 days. This urgency resulted in malleable code rather than a well defined one. This, in turn, became the most powerful asset of JavaScript.

Now, let’s start with the advantage of JavaScript over TypeScript.

  • When it comes to TypeScript vs JavaScript performance, JavaScript is faster in the compilation as compared to TypeScript.
  • JavaScript also supports abstract classes.
  • It has specifically designed tools and or dealing with small scripts.
  • JavaScript does not require expensive development tools. Developers can work with JavaScript on a simple text editor.
  • It supports native browser.
  • Has a large community of followers and is used in 95% of the existing websites on the internet.

Conclusion

TypeScript can, more or less, do everything that JavaScript is capable of. The areas in which TypeScript lacks behind will most likely be updated to perform better in its future updates. Although TypeScript might take the place of JavaScript sooner than we think, but for now JavaScript remains dominant with a bigger developer community and use far more than any other language in existence.