add with two parameters: a and b.a and b.add function with arguments 5 and 7 and print the result.add with two parameters: a and b.a and b.add function with arguments 5 and 7 and print the result.add function with parametersadd that takes two parameters named a and b without type annotations yet.Start by writing a function with two parameters. Don't add types yet.
add function to add type annotations : number to both parameters a and b.Use : number after each parameter name to specify the type.
add function with numbersadd function with arguments 5 and 7 and store the result in a variable named result.Use const result = add(5, 7); to call the function and save the output.
console.log statement to print the value of the variable result.Use console.log(result); to show the sum in the console.
What does a parameter type annotation in TypeScript do?
Which of the following is the correct way to add a type annotation for a parameter named age that should be a number?
function checkAge(____) { return age > 18; }age: number.What will be the output of this TypeScript code?
function greet(name: string) { return `Hello, ${name}!`; }
console.log(greet(42));string parameter named name.42, which does not match the expected string type.Identify the error in this TypeScript function and choose the fix:
function multiply(x: number, y) { return x * y; }x has a type number, but y has no type annotation.y: y: number -> Option CYou want to write a function formatPrice that takes a price parameter which can be either a number or a string. How should you annotate the parameter to accept both types?
| between types.price: number | string to allow either type.| for multiple allowed types [OK]Pass the test and this pattern moves unknown