0

So I'm trying to run these 2 functions in chrome:

function let_test1() {
    debugger;
    let something = true;
    return something;
}

function let_test2() {
    debugger;
    console.log(something);
    let something = true;
    return something;
}

If in let_test1 I try to evaluate something at the breakpoint, I get undefined.

If I try this in let_test2 , I get a ReferenceError.

Any ideas why this happens?

CLARIFICATION

Not sure this is related directly to the TDZ answers since this pertains specifically to the first example resolving to 'undefined' instead of a 'Reference Error' and the question is what causes it. The TDZ in my understanding addresses the 'Reference Error' only.

Should so, why does it resolve to 'undefined' in the first example? As in my current understanding it should throw a ReferenceError.

overburn
  • 1,194
  • 9
  • 27

0 Answers0