JavaScript Fundamentals: Hoisting, TDZ, and Console Methods

🚀 Day 4 / 100 — JavaScript Fundamentals Refresher #100DaysOfCode challenge Today I revised some core JavaScript concepts that every developer should know. These are small things we often overlook… but they’re essential for debugging and writing clean code. Here’s a quick JavaScript revision :👇 🧠 1. Hoisting Hoisting means JavaScript moves variable and function declarations to the top of their scope before execution. console.log(a); // undefined var a = 5; Why undefined? Because var a is hoisted, but the value 5 is assigned later. So internally JS sees this as: var a; console.log(a); a = 5; ⚡ 2. Hoisting with let and const let and const are also hoisted, but they behave differently. They cannot be accessed before declaration. console.log(a); // ❌ ReferenceError let a = 10; Unlike var, they are not initialized during hoisting. 🚫 3. Temporal Dead Zone (TDZ) The Temporal Dead Zone is the time between: • When a variable is hoisted • And when it is declared During this period, the variable exists but cannot be accessed. Example: console.log(a); // ReferenceError let a = 10; The variable a is in the Temporal Dead Zone until the line where it’s declared. This prevents many bugs that happened with var. 🖥️ 4. console.log() The most common debugging tool. console.log("Hello World"); Used to: • Print values • Inspect objects • Debug logic Think of it as a developer’s flashlight 🔦 ❌ 5. console.error() Used to display error messages in the console. console.error("Something went wrong"); Usually appears in red and helps identify critical problems quickly. ⚠️ 6. console.warn() Used for warnings that might cause issues later. console.warn("This feature is deprecated"); Displayed in yellow in most browsers. ⏱️ 7. setTimeout() Executes a function once after a delay. setTimeout(() => { console.log("Runs after 2 seconds"); }, 2000); Common uses: • Delayed UI actions • Notifications • API retries 🔁 8. setInterval() Executes a function repeatedly after a fixed interval. setInterval(() => { console.log("Runs every 2 seconds"); }, 2000); Used for: • Timers • Polling APIs • Real-time updates 💡 Key takeaway: Great developers don’t just chase new frameworks — they master the fundamentals. Revisiting JavaScript basics always uncovers something new. 🔥 Day 4 completed. 96 days to go. #javascript #100daysofcode #webdevelopment #coding #developers #programming #learninpublic #buildinpublic #SheryiansCodingSchool #Sheryians

  • graphical user interface

To view or add a comment, sign in

Explore content categories