JavaScript Truthy vs Falsy Values Interview Question

💡 Interview Question: Understanding Data Types in JavaScript Recently came across an interesting question that tests your fundamental 👇 let a = ''; let b = false; let c = 0; let d = null; let e; let f = {}; let g = []; if (!a) console.log('1') // similarly check for b, c, d, e, f, g 👉 Question: What will be printed in the console for each variable? 🧠 Concept Tested: Truthy vs Falsy values in JavaScript 📌 Falsy values in JS: '' (empty string) false 0 null undefined NaN 📌 Truthy values: {} (empty object) [] (empty array) ✅ Output: 1 2 3 4 5 (Only for a, b, c, d, e → because they are falsy) 🚫 Nothing will be printed for: f = {} g = [] (because they are truthy) 🎯 Key Takeaway: Even empty objects and arrays are considered truthy in JavaScript — a common interview trap! #JavaScript #FrontendDevelopment #WebDevelopment #CodingInterview #InterviewQuestions #Programming #Developers #TechTips #LearnToCode

To view or add a comment, sign in

Explore content categories