×

Why You Should Know TypeScript as a Web Developer

image of Leo Leong
Leo Leong

August 28

TypeScript is an object-oriented, open-source programming language. It's a superset of JavaScript, containing optional typing. Also, it compiles to plain JavaScript. TypeScript is a statically compiled programming language for writing clear and concise JavaScript code. It fulfills the same purpose as JavaScript and can be used for both client-side and server-side applications. In addition, the libraries of JavaScript are also compatible with TypeScript.
image of Why You Should Know TypeScript as a Web Developer

TypeScript Architecture

But why do we need to use TypeScript if it is almost the same as JavaScript?

JavaScript, initially a client-side language, expanded into server-side programming. Yet, its complexity hindered it from excelling as an object-oriented server-side technology. To address this, TypeScript emerged, bridging the gap and offering a more robust solution.

The biggest point of TypeScript is naturally “Type”!

Data in TypeScript requires explicit types, JavaScript does not.

JavaScript
TypeScript

In TypeScript, we need to explicitly define the types of variables, while in JavaScript, the types are inferred at runtime. This means that TypeScript can catch errors at compile time before the code is executed, while JavaScript can only catch errors at runtime. This can help to prevent bugs and make code more reliable.

This becomes particularly beneficial as codebases expand, preventing bugs and reducing complexity. Additionally, it enhances code readability for other programmers by providing clear input and output type expectations for functions. This clarity becomes even more crucial as functions grow in size and complexity.

Pros:

  1. Provides optional strong static typing
  2. Detect bugs earlier
  3. Code is predictable
  4. Extensibility and Reusability
  5. Provide object-oriented writing

Cons:

  1. There is a certain learning cost
  2. Need to write more code
  3. Need to compile
coding JavaScript TypeScript