21.
How can you define default function parameters in ES6?
By adding a separate line of code to handle the default value inside the function body.
By enclosing the parameter in square brackets.
By using the "default" keyword before the parameter name.
By assigning a default value directly to the parameter.
Correct: D
To define default function parameters in ES6, you can assign a default value directly to the parameter when declaring the function. This value will be used if no value or undefined is provided for that parameter when the function is called.
function greet(name = "Stranger") {
console.log(`Hello, ${name}!`);
}
greet(); // Outputs: Hello, Stranger!
greet("Alice"); // Outputs: Hello, Alice!