number, string, boolean, null, undefined.
Let’s create some simple applications using these types -
💡Thing to learn - How to give types to arguments of a function
💡Thing to learn - How to assign a return type to a function
Write a function that calculates the sum of two functions
function sum(a: number, b: number): number {
return a + b;
}
console.log(sum(2, 3));
💡Thing to learn - Type inference
Function name - isLegalCode
function isLegal(age: number) {
if (age > 18) {
return true;
} else {
return false
}
}
console.log(isLegal(2));Â