Typescript Vs JavaScript - advantages of typescript -

Typescript Vs JavaScript is the talk of the town these days. Both have their advantages and disadvantages. In this article, however, we will be discussing both briefly. And we will go a little bit deeper in the comparison of TypeScript Vs Javascript. We will be looking at how these both come into play in an actual real-world web project. and also how both of them benefit from each other.

For experienced developers, the difference is pretty evident. But if you are a beginner you can easily get confused in highlighting the actual essence of both. The question of difference among these two is frequently asked in interviews as well. Most interviewers are looking to find if you have a clear concept about both these things and how would you would and maintain a separation concern between both. Hereby separation of concern, we mean that one should be able to say exactly if an issue at hand is related to javascript or typescript.

What is javascript?

Javascript is a clientside scripting language as you may already know. It is mostly restricted to browser and UI, although nowadays NodeJS (a javascript-based serverside language) is also very popular. But to keep things simple in the start let’s limit our understanding of javascript to a browser-based client-side scripting language. This language helps you do logical stuff on the web. It also helps you manipulate UI to a great extent as most logical stuff is related to or results in some sort of UI manipulation on a webpage.

Javascript was made by Netscape in the early ’90s. Netscape was a huge company at that time, it also had a pretty famous web browser at the time with the same name. Recently you can see some level of an evolved version of that known as firefox. The main concern behind creating this scripting language was to make client-side UI and logical checks quicker.

What is typescript?

Almost a decade after the huge success of Javascript. As every single web browser on the planet started supporting javascript. The realm or concept of Javascript started evolving as well. We saw hundreds and thousands of new Js-based libraries and platforms which worked with javascript under the hood and provided helper functions and new ways to make the process of making your JS-based projects easier and the same time the end project harder to break. JQuery was one of the most famous libraries among this and still is to some extent.

An issue related to typings arrived constantly while engaging with variables. As variables can be assigned new types, such as from string to a number, vice versa. There was chaos seen at some time in any given project with the root cause being the type of the variable. Hence the great minds of Microsoft came together and built a way to keep the definition of types for data consistency. They bundled their best practices for keeping typings of any object together and named it an interface. even provided guidelines on how to manage these interfaces and share interfaces between backend and frontend.

Hence, typescript is a subset of javascript. It is a way to organize javascript typings and prompt errors wherever there is a type mismatch in a project.

Comparison: TypeScript vs JavaScript

Different types in typescript

Here are the 6 predefined types in typescript…

  1. Undefined
    This is the type which is given to an uninitialized variable.
  2. Null
    This is used when object has no value.
  3. Void
    This is a return-type, commonly used with functions.
  4. Boolean
    This type represents a boolean state, either true or false.
  5. Number
    This type is used for both decimal (floating point numbers) and Integer.
  6. String
    The string type is used for strings (sequence of characters).
  7. Any
    This type as the name implies can be used for any of the above mentioned type.

Typescript Vs JavaScript – Benefits of Typescript

Here are some of the most common advantages of typescript over javascript.