Introduction
JavaScript is one of the most famous programming language and is the preferred choice for both frontend and backend. However there are some basic types of errors that a programmer usually faces, examples include simple typos, failure to understand the API surface of a library, some incorrect assumptions about the runtime behavior or other types of errors.
(Source: Tenor)
The goal of using TypeScript is that it acts as a static type checker for your JavaScript programs, or in other words, it’s a simple tool that runs before your code runs and ensures that the types of the program are correct.
(Source: tenor)
Interesting ain’t it? Let’s start with writing our first Program, the famous Hello World Program in TypeScript
Writing the First Program in TypeScript
Before writing the program, it’s recommended that you install the latest stable version of Typescript using the command
npm install -g typescript
This will install the latest stable version of TypeScript on your device.
Let’s get started with the first program of TypeScript, Open up a text editor and create a new file and save it with the .ts extension.
Let us start with the traditional Hello World Example
var message:string = "Hello World"
console.log(message)
To Compile the TypeScript code, Open up the command prompt or the integrated terminal and navigate to the directory where you have saved the code.
The above command on execution will generate a .js file at the same location where the TypeScript source file exists.
The content of the .js file is
var message = "Hello World";
console.log(message);
To run the program written, type the following in the terminal
node Hello.js
The output will be