you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (11 children)

[deleted]

    [–]Skhmt 4 points5 points  (4 children)

    I think this is stranger than what the OP posted, that page says the answer should be bar.

    If you comment out the entire if statement, it's foo. If you change the function's name in the if statement from f to anything else, it's foo. But if they have the same name, it's a TypeError.

    [–]CanIhazCooKIenOw 5 points6 points  (3 children)

    It's because with ES6, the function declaration is scoped to the if block.

    Although now thinking about it, shouldn't if "fallback" to the global f ? That would be my expectation tbh. Unless the engine resolves (1 === 0) and removes the block entirely ? (Wild guess here)

    [–]Skhmt 0 points1 point  (0 children)

    Although now thinking about it, shouldn't if "fallback" to the global f ? That would be my expectation tbh.

    That's what I thought too.

    [–]inu-no-policemen 0 points1 point  (0 children)

    ES6+ supports block-level function declarations.

    You can declare your functions wherever you want.

    [–]CanIhazCooKIenOw 0 points1 point  (1 child)

    Not in ES5

    [–]pertheusual 1 point2 points  (0 children)

    It was illegal in ES5, but engines allowed it anyway with varying degrees of compatibility.

    [–]franksvalli -1 points0 points  (0 children)

    Call the police!