add two numbers in typescript

To add two numbers in TypeScript, you can declare two variables with type number and then use the + operator to perform their addition:

index.ts
let num1: number = 5;
let num2: number = 10;
let sum: number = num1 + num2;

console.log(sum); // Output: 15
109 chars
6 lines

We first declare num1 and num2 variables of type number and assign them values of 5 and 10 respectively. Then, we declare the sum variable and assign it the value obtained by adding num1 and num2. Finally, we log the value of sum which should be 15.

gistlibby LogSnag