TYPESCRIPT | WHAT IS TYPESCRIPT | TYPESCRIPT BASICS

Share the post

What is TypeScript? 

Today, we will see What is the TypeScript? and also what is the advantages of this language. Why we should use TypeScript instead of JavaScript? What is the difference between TypeScript & JavaScript? What is TypeScript Tupples?

TypeScript Defination :

TypeScript is a superset of JavaScript.TypeScript is Object-oriented & compiled language.When you compile your TypeScript code then compiler converts the same into JavaScript & then executes the result. Nowadays, Visual studio code  IDE introduced by Microsoft can provide IntelliSense & also provide some plugin that supports TypeScript.

The Simple TypeScript example is as follows :

message : string;

helloWorldMessage(msg : string){

this.message = msg;

}

console.log(Hello + this.helloWorldMessage('World'));

Basically, TypeScript having all the functionalities of JavaScript plus it has its own features.TypeScript files can be store with the file extension called .ts

In JavaScript variable defined as follows:

var z = 1;

We defined variables In TypeScript like

var z : number = 1;

Simple words typescript comes with the type of variables. let’s take other example :

message : string;

helloWorldMessage(msg : string){

this.message = msg;

}

console.log(Hello + this.helloWorldMessage('World'));

here if you do not assign type for msg then typescript will implicitly assign type any to msg.

The main advantage of TypeScript :

The main advantage of TypeScript it reduces the possibility of undefined error for a variable which we normally faced in JavaScript code while compiling, also we will easily identify the property & methods declare error regarding the type of it.

What is the difference between JavaScript & TypeScript ?

  • The Javascript can save the file by extension .js while typescript save as .ts
  • While compiling the typescript code. It first converts to javascript & then executes it on the browser. Browser doesn’t understand the typescript code.
  • In typescript, we can use the JavaScript code as it is.
  • TypeScript is an object-oriented language while JavaScript is a web scripting language.
  • As TypeScript is the object-oriented language it gives the feature like interface while JavaScript doesn’t have this feature.
  • The compilation time of TypeScript is more than JavaScript.

What is TypeScript Tupples?

In TypeScript, We can save different types of value in single variables. For Example in Array, We can store different types of value in the different indexes.

let tupple_example = ["abcd",1234,"1234"];

As we can seen in above example we are saving different types of values in single variable.

“abcd” : type string

1234 : type number

Leave a Comment