Closed ratneshmurugesangale closed 4 years ago
Declared variable studentName inside block-scope is not hoisted to top of section and below error has been raised.
Yes it is hoisted, that's the whole point of this code and the following 3-4 paragraphs explain exactly that.
Edition: (2nd)
Book Title: You-Dont-Know-JS
Chapter: Chapter 5
Section Title: Scope-closures -> Uninitialized Variables (aka, TDZ)
Problem:
Declared variable studentName inside block-scope is not hoisted to top of section and below error has been raised.
Error Info: Uncaught ReferenceError: Cannot access 'studentName' before initialization at:4:17
var studentName = "Kyle"; { console.log(studentName); // ??? // .. let studentName = "Suzy"; console.log(studentName); // Suzy }