getify / You-Dont-Know-JS

A book series on JavaScript. @YDKJS on twitter.
Other
179.63k stars 33.51k forks source link

ES.Next & Beyond: Chapter-02: Expected Error doesn't occur #1531

Closed danialmalik closed 5 years ago

danialmalik commented 5 years ago

Yes, I already searched for this issue

Edition: 2nd

Book Title: ES.Next & Beyond

Chapter: 02: Syntax

Section Title: Block-scoped Functions

Problem: In the first code block, i.e.

{
    foo();                  // works!

    function foo() {
        // ..
    }
}

foo();  // ReferenceError

in the later call to foo, a ReferenceError is expected. But when I run the code using node, there is no error there.

➜  ydkjs: node                              
Welcome to Node.js v12.7.0.
Type ".help" for more information.
> {
...     foo();                  // works!
... 
...     function foo() {
...         console.log('Called');
...     }
... }
Called
[Function: foo]
> 
> foo();
Called
undefined
> 
getify commented 5 years ago

This book has not been worked on in second edition yet.