Typescript provides you some basic types

number, string, boolean, null, undefined.

Let’s create some simple applications using these types -

Problem 1 - Hello world

💡Thing to learn - How to give types to arguments of a function

Write a function that greets a user given their first name:

Problem 2 - Sum 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));

Problem 3 - Return true or false based on if a user is 18+

💡Thing to learn - Type inference

Function name - isLegalCode


function isLegal(age: number) {
    if (age > 18) {
        return true;
    } else {
        return false
    }
}

console.log(isLegal(2));Â