Computer scienceProgramming languagesTypeScriptIntroduction to TypeScript

What is TypeScript?

Theory

The age of man

Report a typo

You have been given unfinished TypeScript code with typos. The ageOfMan function has an incorrect return type. Also, all function arguments do not indicate that they are optional. The last point is that you need to specify an explicit type for the age argument. Fix the ageOfMan function to make the code work!

Write a program in TypeScript
function ageOfMan(age, name: string): void { //Change this line!
return `${name ?? "User"} ${age ?? 18} years old!`
}

const message: string = ageOfMan();
console.log(message);
___

Create a free account to access the full topic