I have tried to execute the below code in Firefox V30.0 Scratchpad:
function do_something() {
console.log(foo); // ReferenceError
let foo = 2;
}
do_something();
The expected behavior is that my program should throw Reference Error, because I am accessing a let
variable before it's declaration. But, I am not getting the expected behavior, the program got executed and the result is as below
undefined
Can you explain me, why is it behaving so?