Complete the code to declare a function parameter with type number.
function add(a: [1]) { return a + 10; }
string type causes a type error when adding a number.boolean is incorrect for numeric operations.The parameter a must be of type number to add 10 correctly.
Complete the code to declare a function parameter with type string.
function greet(name: [1]) { return `Hello, ${name}!`; }
number or boolean causes errors when concatenating strings.The parameter name should be a string to use in the greeting message.
Fix the error in the function parameter type to accept an array of numbers.
function sum(numbers: [1]) { return numbers.reduce((a, b) => a + b, 0); }
number instead of number[] causes errors because a single number is expected, not an array.The parameter numbers must be an array of numbers, written as number[].
Fill both blanks to declare a function with two parameters: a string and a boolean.
function checkStatus(name: [1], isActive: [2]) { return `${name} is ${isActive ? 'active' : 'inactive'}`; }
number instead of boolean.The first parameter name is a string, and the second isActive is a boolean.
Fill all three blanks to declare a function with parameters: a string, a number, and an optional boolean.
function createUser(name: [1], age: [2], isAdmin?: [3]) { return { name, age, isAdmin }; }
The parameters are name as string, age as number, and optional isAdmin as boolean.