fbpx

TypeScript, what is it and how does it differ from JavaScript?

4 March 2022
Marta LópezShare:

Increasingly, companies are opting for programming languages whose code is scalable, simple and clean. One of the clearest examples is TypeScript which, in just a few years, has become a firm favourite.

TypeScript (TS) is considered a higher level programming language, as it has many advantages for web development and the improvement of the user experience in apps and websites.

TypeScript is a superset of the famous JavaScriptIt is a language that translates the code of this language and, in addition, it has other improvements. In this post, we take a closer look at TypeScript, what it is and how it differs from JavaScript.

What is TypeScript?

Designed by Microsoft in 2012, TypeScript stands out for its versatility; it is also simpler and easier to test, as it allows code to be written with fewer errors. As such, it is the default language that Google uses for Angular development.

TypeScript is an object-oriented language (such as the R languagefor example). This means that both the client and the server have access to write code. In addition, it is open source.

On the other hand, it stands out for being cross-platform and therefore portable. That is to say, can be used from any device, operating system or browser. Like JavaScript, it does not require any specific machine.

In fact, these are not the only characteristics shared by these 2 programming languages:

  • The usage is similar to JavaScript: As TypeScript is based on JavaScript, it is easy to understand, if you already know JavaScript. 
  • JavaScript libraries can be incorporated: TypeScript supports JavaScript libraries. In fact, developers can also use the same JavaScript frameworks and tools.
  • JavaScript is TypeScript: If the extension is changed from .js to .ts, the code written in JavaScript becomes TypeScript.
  • TypeScript code is converted to JavaScript: It should be noted that TypeScript code is not understood by browsers at first. It is therefore necessary to compile it and convert it into JavaScript code. A 'computer translation' that is known as 'trans-piled' or, in English, 'transpilation'.

Why use TypeScript?

TypeScript is characterised by handling different types of data. It is therefore a scalable and secure language, because the execution of its code can be verified. 

Whereas with JavaScript, the data type could not be known until the moment of execution (which leads to errors); TypeScript is a static language, so there is a division of data types.

There are 3 categories of TypeScript data types:

  • Any: This means that a variable can be any type of data.
  • Integrated: In this sense, we see the variables number, boolean, string, null, void and undefined.
  • User-defined: This includes enumeration, array, interface, tuple and class.

TypeScript Tutorial: advantages of using this programming language

So why use TypeScript and what are the benefits of using this programming language?

Here are the advantages of TypeScript:

  • An intuitive language: TypeScript is an easy language to learn, if you know JavaScript. It is also an easy language to read and write.
  • Detects errors in time: TypeScript's precision is ideal. It allows compilation errors to be detected before execution, so it is reliable code with a very low error rate.
  • It facilitates teamwork: Being cross-platform, several developers can work on the same project in unison. 
  • Generates standard code: This is also conducive to reducing potential problems.
  • Static writing: It is not dynamic code, so this type of writing favours improved code structure and object-oriented programming techniques.
  • Effectiveness: JavaScript skills can be used more effectively. Compiled TypeScript, it becomes a safer and cleaner JavaScript.

But what is TypeScript and how does it differ from JavaScript? Still not clear?

TypeScript VS JavaScript: how do they differ?

Now it's time to find out what TypeScript is and how it differs from JavaScript. Here are the most obvious differences:

  • TypeScript is statically typed, whereas JavaScript is a dynamic language.
  • JavaScript does not support modules, whereas TypeScript does.
  • TypeScript has an interface, whereas JavaScript does not.
  • In TypeScript you do have to compile the code, in JavaScript you don't have to.

Discover how to learn TypeScript at our technology institute 

If you already know what TypeScript is and how it differs from JavaScript, it's time to start learning it!

Discover in IMMUNE all our amazing training offer and dedicate yourself to what you like the most. We have very complete programmes for you to become the best web developer. Don't miss our Degree in Software Development Engineeringas well as other formations such as our Web Development Bootcamp

And if you don't have much time, you can start with this Free Python Course

Subscribe to our newsletter
menuchevron-down