Abdelrahman Beaih’s Post

Scope/Hoisting — Ghost Variable The log said undefined. You swore it should crash. It didn’t. The bug hid for weeks. Then prod got haunted. Lesson: var is hoisted and initialized to undefined. let/const are hoisted but in the Temporal Dead Zone. Prefer const, then let, avoid var. A hallway with fog. A label “TDZ” on a locked door. A shadow holding a sign: “undefined”. Caption Version (under 1200 chars): You expected a crash. You got undefined. That’s how the ghost wins. Hoisting isn’t “JavaScript being weird”. It’s JavaScript being consistent. var declarations rise up and become undefined. let/const rise up too, but stay locked in TDZ. If you want fewer hauntings: Use const by default. Use let when you must. Leave var in the basement. Digilians - الرواد الرقميون #JavaScript #CodingStory #WebDev #Scope #Hoisting #Frontend #Bugs #Digilians #MERN_STACK #TDZ

  • text

To view or add a comment, sign in

Explore content categories