JavaScript Interview Questions: Null vs Undefined Explained

🚀 JavaScript Interview Questions Series – Day 1 Question: What’s the difference between null and undefined? 👉 Answer (What interviewers want to hear): 👉 undefined: A variable that has been declared but not assigned a value. let x; console.log(x); // undefined 👉null: An assignment value that represents “no value” or “empty.” let y = null; console.log(y); // null 🔑 Key Differences: undefined is the default state of uninitialized variables. null is an intentional assignment to indicate “nothing.” 👉Type check: typeof undefined → "undefined" typeof null → "object" (quirk in JS!) 👉Equality: null == undefined → true (loose equality) null === undefined → false (strict equality) 💡 Interview Tip: When asked, don’t just define them—show you understand the intent: Use undefined for system-level absence (not yet assigned). Use null when a developer explicitly clears a value. ✨ That’s Day 1! Follow along for more JavaScript interview prep nuggets in this series. What’s your favorite tricky JS question? Drop it in the comments 👇 #JavaScript #InterviewQuestions #WebDevelopment #TechInterviews #LearnToCode #CareerGrowth

To view or add a comment, sign in

Explore content categories