Typescript hello world

Let us start TypeScript programming with simple “Hello World!” example.

Create and save the file with .ts extension. In first line we declare a variable of string type. In second line we display the variable’s value at the terminal window.

TypeScript Hello World:

var message:string = "Hello World!" ;
console.log(message);

As we discussed in earlier tutorials that TypeScript code will be converted into JavaScript Code. After the compilation of above TypeScript code following JavaScript code will be generated.

Translated code:

var message = "Hello World!";
console.log(message);

Compile and Execute a TypeScript Program:

Comiple: Use below command on the terminal window for compilation. tsc typeScriptFileName.ts Note − Multiple files can be compiled at once. tsc typeScriptFileName1.ts, typeScriptFileName2.ts, typeScriptFileName3.ts

Execute: Use below command on the terminal window for execution. node typeScriptFileName.js

Please follow and like us:
Content Protection by DMCA.com