JavaScript hoisting: A reminder of its quirks

JavaScript reminder that hit me again today 😅 Not all “functions” in JS behave the same. Hoisting treats them completely differently depending on how you write them. // 1. Function declaration sayHi(); // works function sayHi() { console.log("Hello"); } // 2. Function expression with var sayHi(); // TypeError: sayHi is not a function var sayHi = function () {}; // 3. Function expression with let/const sayHi(); // ReferenceError const sayHi = () => {}; Same idea… totally different behavior. Function declarations get lifted fully. var just gets hoisted as undefined. And let / const sit in the “don’t touch me yet” zone. It’s wild how many bugs come from just this one thing 😅 JavaScript keeps us humble. #javascript #webdevelopment #codinglife #frontend #devhumor

  • graphical user interface, text, application, chat or text message

To view or add a comment, sign in

Explore content categories