JavaScript Condition: Truthy vs Falsy in If Statement

🧠 This JavaScript Condition Looks OBVIOUS… But Is It? 👀 Most people answer this in 2 seconds 😄 And that’s where the mistake happens. let a = []; if (a) { console.log("Yes"); } else { console.log("No"); } No functions. No loops. Just one if. Still… comments will be very different 👀 🤔 Why this question is interesting Tests truthy vs falsy Many think [] is falsy Very common interview trap Easy to read, tricky to reason Everyone feels confident to comment 💬 Your Turn Comment your answer 👇 Output → Why? → ⚠️ Don’t run the code. Answer based on understanding. I Will post the correct output + simple explanation in the evening. 📌 This post is to strengthen JavaScript basics, not to confuse beginners. #JavaScript #LearnJS #FrontendDevelopment #CodingInterview #TechWithVeera #WebDevelopment

  • No alternative text description for this image

output of its is true why because it give in javascript when we pass the value to if, while, &&, || it convert to the Truthy or false a = [ ] is an empty array when we execute the code it show true value OUTPUT : YES

Like
Reply

Take this to the next level: If(!!a == “true”)

Yes bcz non primitive is truthy value

Like
Reply

The Output is "Yes"

Like
Reply
See more comments

To view or add a comment, sign in

Explore content categories