Загрузка...

Hoisting and the temporal dead zone (JS's weirdest feature)

console.log a variable before you declare it. JavaScript should crash. But it doesn't. Why?

What's covered:
• console.log(x) on line 1, var x = 5 on line 2 → prints `undefined`, not an error.
• Hoisting: var and function declarations get moved to the top of their scope.
• Only the declaration is hoisted, not the assignment.
• let and const are also hoisted — but they sit in the 'temporal dead zone' until declared.
• Takeaway: use let and const, hoisting bugs disappear.

Save this. Then never use var again.

#pixelgridui #javascript #js #hoisting #webdev

Видео Hoisting and the temporal dead zone (JS's weirdest feature) канала Pixel Grid UI
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять