JavaScript vs Typescript, which should you choose?

Joshua Okoro
UpSkillie
Published in
7 min readJan 3, 2020
Photo by Pablo García Saldaña on Unsplash

The rise of JavaScript in the web development community grew rapidly, and it’s still growing as more frameworks and tools are been developed to simplify the works of developers to meet the unending demand.

Before JavaScript became the choice for everything, there were languages like, PHP — that was used and still used by Facebook — and Java to develop and maintain web applications. Those languages were so popular years back no one ever thought there would be a shift. No one saw JavaScript taking over both front and back end of web development. So what happened and how did we get here?

What is JavaScript and how did it become almost everyone’s favorite?

We can start by looking a bit into its history, which almost every web developer knows.

JavaScript is a scripting language that was developed by Brendan Eich when he was working at Netscape for their web browser — Netscape Navigator. Its purpose was to provide interactivity on a webpage. For that, one of the rules was for it to be a client-side program that runs on web browsers without needing any compilation, like other programming languages.

Taking into account it was designed to provide interactivity on a web page, everyone fell in love with it. Webpages were no longer boring and static. A user can interact with any part of a web page and receive different kind of responses. It became the talk of the town. Interactive web pages were on high demand and developers loved how easy and fast it was to write snippets for their websites.

Along the line, things started changing. Websites started getting bigger and demands increased. They started having multiple pages that needed interativity. This means developers would have to write more snippets to cover everything. Those programs written were no longer snippets, instead files and folders.

Even though more code was written to achieve these goals, everyone still loved it because of the easy and how fast it executed. This sprung the possibilities of having JavaScript at the front and back end of web development and even mobile apps. Then came the era of Node.Js for the backend, React, Angular, Vue, Ember, and the list goes on for frontend, and React Native for mobile.

It was great and we are still in that era, but things are changing again. We have a new language called— Typescript — that was introduced recently into the JavaScript community. According to its creators, it’s not here to takeover JavaScript but to assist it. So no need to ditch JavaScript before this article is over, instead lets checkout what TypeScript is all about and what it’s bringing to the table.

What is TypeScript and why is it gaining attention.

TypeScript is a typed superset of JavaScript that compiles to plain JavaScript.

The definition alone gives you a plain understanding of what it’s all about, but I can still expand more on it if you like.

It’s a typed language — because Javascript isn’t, so it’s trying to fill in the gap of JavaScript been loosely typed. Let me give an example on that. Take for instance Java, a typed language. When you declare a variable, you have to define what data type that variable will accept — say a number — if you try assigning anything other than a number to that variable later in your program, it will throw an error. Knowing that, in JavaScript it’s a different universe. You can declare a variable and assign any data type to that variable later in your program without having an error. I hope that clearifies things.

Moving on, that’s not all about TypeScript. It compiles to plain JavaScript. Which means when you are done writing all your program, its compiler interprets all your code into a JavaScript language to be used where needed.

So truly, it’s not here to replace JavaScript because it’s still passing everything down to JavaScript. It’s just helping and likely going to make JavaScript more popular and stronger. So you right if you call it JavaScript’s Assistant — assisting to JavaScript to achieve some things it couldn’t.

At present, it’s gaining love from developers. Especially most people from typed languages like, Java, Visual Basic and C++, and now moving into the JavaScript universe. These developers love writing their programs in TypeScript.

The big question now is, which should you choose when you building your next project?

Choosing JavaScript or TypeScript

To answer this question, we must look at some of their weaknesses and strength. This can determine is you choose either for your next project or hold on to what you have right now.

Popularity

Javascript has been around since 1995. That’s a long time to be more popular than TypeScript that made its first appearance in October 2012. With that clear advantage, you can see below that it remains more popular.

Image from Google Trends

On the other hand, things are changing. Even though TypeScript just barely came into the game, it’s starting to pick up pace on popularity, which you can see on the graph above.

Learning Curve

JavaScript is easy to learn. Everyone knows that. You don’t have to bother about so many things you worry about in other languages. This gave JavaScript its popularity in the first place. You can find almost everything about it out there to get started or advance your knowledge.

TypeScript, on the other hand, might not be easy for some set of people, like beginners. This is because they would have to learn a half or high percentage of JavaScript before moving onto TypeScript. For those already familiar with JavaScript or those with previous knowledge of a Typed language, it will be easy to pick up TypeScript. The documentation is one of the best out there to learn from.

JavaScript Community

Since JavaScript has been around for a long time and it’s loved by almost everyone, this has helped its community grow. It has it’s community one of the biggest out there.

There are almost 2 million questions asked in the JavaScript StackOverflow community and 767 thousand members with more than 2 thousand online in the Reddit community. It’s easy to find solutions to problems and there are people always online ready to help.

TypeScript Community

The community is not so big at this point with 100 thousand questions asked in StackOverflow, and 29 thousand members with more than 70 online in Reddit.

However, one thing it has is good documentation — that I mentioned previously. With it, It’s simple to navigate to find solutions. TypeScript might not have the numbers as JavaScript right now, but one thing I am sure about is, as the popularity grows the community will increase in numbers.

Performance

On performance, they are the same. Having your program written in JavaScript or TypeScript is not going to change anything on how your program performance. If written in TypeScript the code will be compiled to plain JavaScript that will be executed.

Benefits of JavaScript

  1. Flexibility — flexibility in the sense that, it’s easy to learn and create what you want faster. And anyone can learn it not needing prior knowledge of any language.
  2. Freedom to do whatever you want with any object — you can add or remove any value of any data type to and from an object without hitting a type error or creating another object.
  3. Huge and support of dependencies — the NPM is a good example of where packages are hosted. There are millions if not getting to billions of packages out there that you attach to your project to accelerate your work. And some of those packages are easy to use, well documented and maintained to have as dependencies.

Benefits of TypeScript

With TypeScript, you get

  1. Type checking while coding — so if you writing your program in TypeScript, it automatically checks for type error. If there is any, it notifies you, therefore preventing type errors before compile-time and production.
  2. Better collaboration — with type checking in place and with functions or variables and constants already typed, others using your code can better understand what data types are accepted and returned by your program.
  3. Low type error in production — ever had a program in production crash because of a wrong type of data passed into the program? Well, that is what TypeScript aims to solve. By reducing type error in production, developers can worry less about it and focus on other things.

When to choose

This is the part that might seem difficult for some, but here is the thing.

As an individual

If whatever you are working on is just some solo project that won’t scale to a huge size in the future, using JavaScript might just benefit you more, because you can get that program up and running without having to spend more time on TypeScript.

As a company

As a company, you will be considering the cost of training your employees to adopt this new language for development. Well, according to ATD, the average cost of training an employee is $1,252. Considering that, is it going to pay off?

Well, just know the source file is going to be larger which means more time to type those syntaxes by developers. If you have lots of developers that will be contributing to the project, also keep in mind developers sometimes make mistakes and mistakes lead to cost of time and money. However, when that project is done and is in production, it’s going to have less data type errors and later on, easy to maintain. This is where TypeScript shines more than JavaScript. This is where it might benefit you as a company.

Conclusion

I’m sure you must have made your decision by now, but it’s also important to know that JavaScript and TypeScript are just tools to achieve what you want to achieve. There is no point sticking with one if it doesn’t serve the purpose you want it to serve. With that been said, thank you for your time.

Happy coding!

--

--