Here is a normal function in JavaScript:
function add(num1, num2) {
return num1 + num2;
}
We can set type for num1
and num2
using a colon.
Here is the equivalent TypeScript code:
function add(num1: number, num2: number) {
return num1 + num2;
}