Menu

Serupa Tapi Tak Sama! Inilah Perbedaan Typescript dan JavaScript

Taufik Nurhidayat
4 min read
#programming

TypeScript and JavaScript are popular programming languages today. So what are the differences between these two programming languages?

social_cards/ts_js_z71ocz.png

TypeScript and JavaScript are both popular programming languages today. Although these two programming languages are related, there are significant differences when we use them. With this article, we will find out what the differences are between TypeScript and JavaScript.

What is JavaScript

JavaScript is the most popular programming language today, created by Brendan Eich in 1995. This language was created for Netscape, as part of the newly developing browser at that time.

Currently, JavaScript has evolved and is used in various programs. Among them are Websites, Games, Mobile Applications, Desktop Software, and even servers running with NodeJS.

JavaScript Features

1. Client-Side Execution

JavaScript is a front-end language that can perform calculations without having to contact the server every time. This can make a website more interactive, save time, and increase efficiency.

2. Input Validation

JavaScript can detect input errors before they are sent to the server, such as empty or invalid input.

3. Platform Independent

Because JavaScript is a client-side programming language, it is important to be independent. Thus, it is compatible to run on various operating systems.

What is TypeScript

TypeScript is an open-source programming language created by Microsoft in 2012. This programming language is built on top of JavaScript, by adding various features that simplify the development process.

All TypeScript code will be compiled into JavaScript before execution. So what can be done with JavaScript can also be done with TypeScript. However, it should be noted that TypeScript is stricter, so there are some things that cannot be done. For example, as follows:

let count: number = 1
count = "satu"
console.log(count)

// error TS2322: Type 'string' is not assignable to type 'number'

TypeScript Features

1. Static Typing

Unlike JavaScript, which is dynamically typed, TypeScript is a statically typed programming language. This means that every variable to be written must have its type determined first.

This feature provides an advantage for users to detect errors earlier and resolve them faster.

2. Compatibility

TypeScript will be recompiled into JavaScript. Thus, it is very important to be compatible with older and newer versions of JavaScript.

3. Additional Features

TypeScript is a JavaScript programming language with various additional broader development features. Among them are supporting OOP concepts such as interfaces, classes, and even supporting integration with text editors such as VS Code.

Why was TypeScript created if JavaScript already existed?

As JavaScript’s popularity increased, this programming language could be used beyond websites. For example, by using NodeJS, we can use JavaScript on the server side.

However, problems arise because the larger the program created, the more complex the code written. Thus, errors in the code are more difficult to solve.

To overcome this, Microsoft developed TypeScript, which is JavaScript with various additional features.

Differences between TypeScript and JavaScript

Learning Curve

Although the TypeScript programming language was created to simplify development, it takes time to learn it. Unlike JavaScript, which is very easy to learn.

Even before learning TypeScript, it is recommended to have JavaScript knowledge first.

Feature Differences

As mentioned earlier, TypeScript is JavaScript with various additional features. Thus, TypeScript has more features than JavaScript.

These additional features make it easier for developers to develop and maintain their programs.

Typing

TypeScript is statically typed and supports OOP (Object-Oriented Programming) concepts.

Conversely, JavaScript only supports dynamic typing and does not support OOP concepts.

Developer Community

TypeScript is a newer programming language than JavaScript. In addition, JavaScript is also more widely used than TypeScript. Theoretically, the JavaScript community is larger than TypeScript.

Not only that, developers who master TypeScript also certainly master JavaScript. This strengthens our theory that the JavaScript community is larger than TypeScript.

Compilation

Before the code is executed, TypeScript will be compiled into JavaScript. Conversely, in JavaScript, the code will be executed directly instead of being compiled first.

TypeScript vs. JavaScript: Which is Better?

Which is better between TypeScript and JavaScript? If viewed from the development, maintenance, and features offered, then TypeScript is the best.

However, if viewed from the ease of learning a programming language, then JavaScript is the best compared to TypeScript.

When to Use TypeScript

If you are creating a large project, involving many programmers, and prioritizing scalability, then use TypeScript.

Meanwhile, for smaller projects that require quick completion. You can consider JavaScript as the programming language to use.

Conclusion

After we know the differences between TypeScript and JavaScript, the conclusion is that TypeScript is JavaScript with various additional features. With these features, it makes it easier for programmers to develop their projects.

With these differences, we are more careful in choosing which language to use.