Curious About Code? Get to Know TypeScript vs. JavaScript in Node.js.

May 24, 2024
JavaScript vs TypeScript graphic with logos

You may have heard of JavaScript, Node.js, and TypeScript. You may even know that they are programming languages used in modern software development. But, alas, you may be a non-technical person who doesn’t understand TypeScript vs. JavaScript, how they are related, and how they are different. In this post, I will explain the three technologies.

First, A Quick Primer on Programming Languages

Programming languages are essentially convenient ways of telling a computer what to do, but you can think of them as tools. As such, each language is a little different and, hence, is a little better (or worse) at getting computers to do specific things.

An important detail to understand is that, especially with modern languages, they actually come in two parts:

  1. the language itself, which the programmer uses to write code, and
  2. another program that understands your code and knows how to translate your code into instructions for the computer, which in the case of Javascript is called a “runtime environment”

A single line of JavaScript could represent hundreds of tiny steps a computer processor needs to carry out. The runtime figures all that out for you.

You can think of a programming language as a tool that is used to make other tools. Imagine having a 3D printer that prints 3D printers. Or imagine using a knife to carve another knife into a different, bigger knife. Does this make sense? (No, it does not, which is why everyone keeps getting hacked. But this is also what makes computers so powerful.)

Now, as we look at TypeScript vs. JavaScript, let’s start with JavaScript.

Think of a programming language as a tool used to make other tools.

What is JavaScript?

Javascript

JavaScript is a programming language. C#, C++, Python, and Java are examples of other programming languages you may have heard of. Generally speaking, the JavaScript “runtime” is a web browser like Chrome. When you go to a modern website, your browser will get some JavaScript code in addition to all the text and pictures that make up the website. Your browser will run this JavaScript code to check user input for errors and send data back to the server.

JavaScript is a very accessible programming language:

  • all modern browsers understand it
  • it’s easy to learn
  • you can write a lot of code very quickly with it

While some languages feel like trying to navigate a giant bureaucracy, JavaScript often feels spontaneous and informal. No proof of residency? No problem! Staple a picture of your dog sitting on the porch to your file, and that’s good enough. The title for your car is actually for a different car? Who cares! Cross it out, write in the correct VIN, and initial it, and you’re good to go. Can’t see without your glasses? Just super-duper promise you’ll wear them, and we’ll see you on the road.

What is Node.js?

Node JS

Node.js is essentially the JavaScript language that uses a different runtime. Remember, the “runtime” is a program that understands how to turn your JavaScript code into all the little steps your computer understands. Node.js allows JavaScript programmers to use the language they already know and love to do even more things.

The key difference is that the “vanilla” JavaScript runtime is part of the browser, and there are a lot of constraints the browser places on what JavaScript is allowed to do. The Node.js runtime is its own separate thing, which means you can write JavaScript programs that run in an environment other than a browser.

One prominent example is using the JavaScript language to write web servers. When you buy something on a website, your computer (or phone) sends a message to a program running on a computer somewhere. Programmers often refer to this as the “back-end”. Node.js allows programmers to write this back-end in the JavaScript language.

In short, Node.js is JavaScript in more places than just browsers.

Understanding TypeScript vs. JavaScript

So, if we have JavaScript in Node.js, and it’s easy to use, where does TypeScript come into play? I mentioned that JavaScript often feels informal. This can be a good thing: it can be really frustrating to need to change seventeen files just to be able to send one little extra piece of data through the system. Allowing for ad hoc changes can speed up development time and reduce redundant, boiler-plate code.

But there are drawbacks, too. Imagine I tell you I’m going to mail you a picture of a blue car. When you open the envelope, you see something like a blue car with two wheels instead of four. Is this image correct? Suppose I tell you, “Blue cars have two wheels, and red cars have four wheels.” This may be fine for one kind of picture, but if I send many kinds of pictures, each with its own complicated rules, you won’t be able to remember it all. You’ll make mistakes. You need some kind of reminder that red cars have four wheels, blue cars have two wheels, and so on.

What is TypeScript?

Typescript

TypeScript is JavaScript with reminders. These reminders are called “types,” hence TypeScript. Thus, TypeScript is a language, not a runtime. In fact, TypeScript uses another program, called a “compiler,” to turn these reminders into plain JavaScript. The JavaScript that the TypeScript compiler produces is what ultimately runs in the runtime.

TypeScript is JavaScript with reminders.

The most obvious benefit of these reminders is that you can keep track of all the different things in your code, how they behave, and so on. But an added benefit is that the TypeScript compiler will double-check all your reminders to ensure they all “line up” and make sense.

If I say I’ll send you a picture of a blue car, but I put it in an envelope for a red car, TypeScript will point out to me that I’ve made that mistake. It won’t let me send the letter until I fix it. On the other hand, JavaScript will let you take an envelope for a blue car and put a snake in it. In other words, considering TypeScript vs. JavaScript, I find TypeScript helps me write better code by reminding me what the other parts of my code are like, and it holds me to those definitions.

In short, JavaScript is a programming language that runs on web browsers. It’s easy to use, but it lacks discipline. TypeScript is a way to write JavaScript that is a bit more mature, as it removes a lot of the guesswork. Node.js is a way to run JavaScript in places other than a web browser.

Explore our work.

Check out our client project stories, including those using TypeScript, JavaScript, and Node.js.

See SEP’s Case Studies »

You Might Also Like