Important Points to Remember about TypeScript
- TypeScript is not like a strictly typed programming language such as C#. The type declaration is not that strict.
- A TypeScript file has the extension .ts.
- Finally, the TypeScript language contains most of the features of ES6 (ECMA Script 6).
Introduction to Programming in TypeScript
The following program declares three variables of number type and one variable of string type. As shown below, we declare variables using var keyword and specify data type after the : symbol. Then, few arithmetic operations are performed. After that, we use the console.log() method to display the output on the console.
var student_name:string="Jolly" var marks1:number=78 var marks2:number=57 var marks3:number=86 var total, percentage total = marks1+marks2+marks3 percentage=(total * 100)/300 var str:string str="Total Marks: "+total console.log(str) str="Percentage: "+percentage console.log(str)
var student_name = "Jolly"; var marks1 = 78; var marks2 = 57; var marks3 = 86; var total, percentage; total = marks1 + marks2 + marks3; percentage = (total * 100) / 300; var str; str = "Total Marks: " + total; console.log(str); str = "Percentage: " + percentage; console.log(str);
Compile and run the above program. It produces the output as shown below.