JavaScript Fundamentals: Loose vs Strict Equality, Hoisting, and Closures

🚀 Day 2/30 – Frontend Interview Questions Series Let’s level up your JS fundamentals today 💡 ❓ Q1: What is the difference between "==" and "===" in JavaScript? 👉 "==" (Loose Equality) - Compares values after type conversion - Example: 5 == "5" // true 👉 "===" (Strict Equality) - Compares value + type (no conversion) - Example: 5 === "5" // false ✅ Best Practice: Always use "===" to avoid unexpected bugs. --- ❓ Q2: What is Hoisting in JavaScript? 👉 Hoisting is JavaScript's behavior of moving declarations to the top of their scope. Example: console.log(a); // undefined var a = 10; 🔍 Behind the scenes: var a; console.log(a); a = 10; ⚠️ Note: - "var" is hoisted with "undefined" - "let" and "const" are hoisted but stay in Temporal Dead Zone (TDZ) --- ❓ Q3: What is Closure? 👉 A closure is a function that remembers variables from its outer scope, even after the outer function has finished executing. Example: function outer() { let count = 0; return function inner() { count++; console.log(count); }; } const counter = outer(); counter(); // 1 counter(); // 2 💡 Closures are widely used in: - Data hiding - Callbacks - React hooks #JavaScript #FrontendDeveloper #InterviewPreparation #ReactJS #WebDevelopment #CodingInterview

To view or add a comment, sign in

Explore content categories