15.
What will be the output of the following code?
function greet(firstName){
function SayHello() {
alert("Hello " + firstName);
}
return SayHello();
}
greet("Steve");
TypeError
Hello
Hello undefined
Hello Steve
Correct: D
The function greet takes in a parameter firstName and defines an inner function SayHello that alerts Hello concatenated with the value of firstName. The greet function is then invoked with the argument Steve. Since the SayHello function is returned and immediately invoked, it will alert Hello Steve.