What would be the output of the following code? [Scoping in JavaScript]
@Yomesh Gupta
Consider the follow code snippet. What would be the output if we invoke the print
function?
var name = "Yomesh";
function print(name) {
console.log(name);
var name = "Ajay";
console.log(name);
}
print(name);
Option 1
undefined Ajay
Option 2
Ajay Ajay
Option 3
Yomesh Ajay
Option 4
undefined Yomesh
Option 5
Error
Option 6
Ajay Yomesh