Difference Between JavaScript and TypeScript

Omerko
5 min readOct 6, 2021

--

Difference Between JavaScript and TypeScript
Difference Between JavaScript and TypeScript

Which do you prefer? JavaScript or a TypeScript? Do you know the difference between those two?

Well, the plan for today's post is to see both technologies, are similar, what are the differences, advantages, and disadvantages for both.

If you would like to see this post in a video format, just click the link down below.

Difference Between JavaScript and TypeScript → https://youtu.be/9i-tDX-vnJY.

What is JavaScript?
What is JavaScript?

What is JavaScript?

First of all, let’s see what is JavaScript.

So JavaScript is a Programming Language that is used since 1995, but initially, it was known as Mocha. Through the years JavaScript improved and it's named changed from Mocha, through EcmaScript to the language known today as JavaScript.

In today's era, JavaScript shaped and formed modern Web Development. As of today, we have multiple helpful technologies that are working closely with JavaScript. Such technologies would be Angular, React, Vue and others.

JavaScript advanced even further and now it is also supporting the back-end side and for it, it can use technologies like Node.js, Express.js, and so on.

What is TypeScript?
What is TypeScript?

What is TypeScript?

TypeScript on the other hand is a technology that was created as a superset from JavaScript. That means that for every feature that JavaScript supports, TypeScript will support also it.

It was developed by Microsoft and to this day it is still maintained by Microsoft. It is designed in such a way that it can develop and maintain large-scale applications.

So, why TypeScript if we already have JavaScript?

Well, back in the days, JavaScript was only used on the client-side. Today, JavaScript is much more than Client Side Language. We can also use Node.js which can run JavaScript Environment so we can use it on the back-end side.

So, by that, JavaScript became complex, even though its syntax and features are easy enough. It is still harder to read, maintain and debug JavaScript code.

Microsoft saw that as an opportunity and they came with the idea of TypeScript. The typeScript was introduced to us as a more strict language. Starting from its name, it was primarily used to add proper, strict types into the code.

JavaScript Example:

Let’s say that we have a user object with a name property.

user = {
name: 'John Doe'
}

Now, let’s change that name property to a number value for example.

user = {
name: 25
}

This won’t throw an error in JavaScript, as there is no strict way of working, no strict types unless we specify those.

TypeScript Example:

Let’s now have the same object but in TypeScript.

user = {
name: 'John Doe'
}

Let’s update that same name property with a number.

user = {
name: 25
}

Just by trying this, you would see an error, and it would say something like this. Type ‘number’ is not assignable to a type of string.

As our name property was initially a string, in TypeScript, we cannot override it with the different data types.

So by this, Microsoft was able to build a more strict way of coding and with that shrink the gap that was in JavaScript code.

Difference Between JavaScript and TypeScript
Difference Between JavaScript and TypeScript

Difference Between JavaScript and TypeScript

Today, we can openly say that TypeScript itself is just JavaScript with types. Initially, it came with much more features.

Next to those strict types, TypeScript is also an Object-Oriented Programming Language, while JavaScript is Scripting Language.

Typescript also supports something called Modules, and by those, we can organize our project better, maintain our code easier while JavaScript doesn’t support that, and on top of that, we have to do all those things manually.

One also cool feature that came with TypeScript is an Interface. By declaring an Interface, we would have an option to create our custom types and not always refer only to prebuilt types.

Preferring TypeScript
Preferring TypeScript

Preferring TypeScript

I prefer TypeScript and here is why.

Maybe for some of the portfolio, smaller projects I would rather use JavaScript, but for more scalable Web Applications, I would use TypeScript.

Next to TypeScript, I do work with technologies like Angular and Nest.js and both of those utilize TypeScript quite extensively. This has to be one of the main reasons why do I prefer TypeScript in the first place.

Here are more advantages of TypeScript, with the strict types that TypeScript has, we are excluding any shape or form of mistyping, and for me, that is a big deal.

TypeScript also compiles our code and while doing that, it can show us errors in our code, so we can fix those before deploying our application.

Disadvantages of Using TypeScript
Disadvantages of Using TypeScript

Disadvantages of Using TypeScript

So, are there any crucial disadvantages themselves?

Well, there is one that can affect large-scale applications.

It can take a lot of time to compile our code. This is not so visible in smaller web applications, but when we are having larger scale applications with custom pipelines, checks, and compilation, it can take some time.

Make Sure to Subscribe
Make Sure to Subscribe

Make Sure to Subscribe

Just to mention one more thing, I did say that I prefer TypeScript over JavaScript, but that is just my personal opinion.

Once again, if you would like to take a look at the video format of this post, just click the link down below.

Difference Between JavaScript and TypeScript → https://youtu.be/9i-tDX-vnJY.

Also, make sure to Subscribe, as I am posting new content weekly.

--

--

Omerko

Hey guys, Omerko here, self taught web developer. Next to Web Development, I am also an Online Instructor. You can find me on YouTube, Udemy and SkillShare.