Why Typescript is the better choice than JavaScript?

➡️ Typescript is an open source language which builds on JavaScript.

➡️ One of the world's most used tools,by adding by adding static type definations.

1. According to StackOverflow servey

➡️ It's mentioned among the five most promising language.

➡️ About 66% percentage of JavaScript programmers already use Typescript and 22% wish to try.

3. What is TypeScript?

➡️ Typescript is subsets of JavaScript that has optional typing and compiles to plain JavaScript.

➡️ Typescript technically is JavaScript with static typing, whenever you want to have it.

➡️ Actually a study shows that 15% of all JavaScript bug can be detected by Typescript.

2. Can we use on the frontend or the backend?

➡️ Typescript is compiled to JavaScript, therefore Typescript can be used anywhere JavaScript could be used: both the frontend and or the backend.

3. Types of Typescript

➡️ Typescript has a variety of basic types, like Boolean, Number, String, Array and Tuple, ETC....

Some of this don't exist in JavaScript.

snippet-typescript.png

4. Reason to choose Typescript over JavaScript

➡️ Typescript is more reliable.

➡️ Typescript is more explicit.

➡️ Typescript and JavaScript are practically interchangeable.

🚥🚥🚥🚥 The End 🚥🚥🚥🚥

Comments (1)

Purvi Barot's photo

TypeScript is a superset of JavaScript which primarily provides optional static typing, classes, and interfaces. One of the big benefits is to enable IDEs to provide a richer environment for spotting common errors as you type the code.

Example:

  • As an example, here's some TypeScript.

    class Greeter {
      greeting: string;
      constructor (message: string) {
          this.greeting = message;
      }
      greet() {
          return "Hello, " + this.greeting;
      }
    }
    
  • And here's the JavaScript it would produce

    var Greeter = (function () {
      function Greeter(message) {
          this.greeting = message;
      }
      Greeter.prototype.greet = function () {
          return "Hello, " + this.greeting;
      };
      return Greeter;
    })();
    

Notice how the TypeScript defines the type of member variables and class method parameters. This is removed when translating to JavaScript but used by the IDE and compiler to spot errors, like passing a numeric type to the constructor.