Complete the code to declare an optional parameter in the function.
function greet(name[1] string) {
console.log(`Hello, ${name}!`);
}Complete the function call to use the optional parameter correctly.
function greet(name?: string) {
if (name) {
console.log(`Hello, ${name}!`);
} else {
console.log('Hello!');
}
}
greet([1]);Fix the error in the function declaration to make the second parameter optional.
function multiply(a: number, b[1] number): number { return a * b; }
Fill both blanks to create a function with an optional parameter and a default value.
function greet(name[1] string[2] = 'Guest') { console.log(`Hello, ${name}!`); }
Fill all three blanks to create a function with two optional parameters and default values.
function createUser(name[1] string[2] = 'Anonymous', age[3] number[4] = 18) { console.log(`Name: ${name}, Age: ${age}`); }
