subtract two numbers in typescript

To subtract two numbers in TypeScript, you can use the subtract operator -. Here's an example:

index.ts
let num1: number = 10;
let num2: number = 5;
let result: number = num1 - num2;
console.log(result); // Output: 5
113 chars
5 lines

In this example, num1 and num2 are the numbers being subtracted, and result is the difference between the two. When we log the value of result to the console, we get the output 5, which is the result of subtracting num2 from num1.

You can also subtract two numbers directly when declaring a variable:

index.ts
let result: number = 10 - 5;
console.log(result); // Output: 5
63 chars
3 lines

In this case, the value of result is calculated by subtracting 5 from 10 directly in the variable declaration.

gistlibby LogSnag