I used to think == and === were just “style choices” in JavaScript. They’re not. That assumption once caused a bug that took me way too long to trace. Examples like: 0 == false → true "" == 0 → true null == undefined → true [ ] == false → true made me pause and actually understand what’s happening. Loose equality (==) compares values after type conversion. Strict equality (===) compares value and type, no guessing, no surprises. The scary part? Code with == can look correct and still behave unexpectedly, especially with user input, API data, or conditionals. My biggest learning: Use === by default. Only reach for == when you clearly understand every conversion involved. Have you ever faced a weird bug because of ==? #JavaScript #FrontendDevelopment #WebDevelopment #LearningInPublic #DeveloperJourney
JavaScript Equality Gotcha: == vs ===
More Relevant Posts
-
Most developers think closures are some kind of JavaScript “magic”… But the real truth is simpler—and more dangerous. Because if you don’t understand closures: Your counters break Your loops behave strangely Your async code gives weird results And you won’t even know why. Closures are behind: React hooks Event handlers Private variables And many interview questions In Part 7 of the JavaScript Confusion Series, I break closures down into a simple mental model you won’t forget. No jargon. No textbook definitions. Just clear logic and visuals. 👉 Read it here: https://lnkd.in/g4MMy83u 💬 Comment “CLOSURE” and I’ll send you the next part. 🔖 Save this for interviews. 🔁 Share with a developer who still finds closures confusing. #javascript #webdevelopment #frontend #programming #reactjs #learnjavascript #softwareengineering #coding #devcommunity
To view or add a comment, sign in
-
🛑 This JavaScript Output Confuses Almost Everyone (Even Seniors) Looks very simple, right? Most people answer this confidently… and still get it wrong 😄 console.log(isNaN("hello")); console.log(Number.isNaN("hello")); console.log(isNaN(NaN)); console.log(Number.isNaN(NaN)); No loops. No async. Just NaN. Yet… answers in comments will be all over the place 👀 🤔 Why this question is interesting Tests real understanding of NaN Shows difference between global vs strict checking Very common interview question Looks easy → causes overconfidence Everyone comments something 💬 Your Turn Comment your answers like this 👇 Line 1 → Line 2 → Line 3 → Line 4 → ⚠️ Don’t run the code. Answer based on understanding. I will post the correct output + clear explanation in the evening. 📌 This post is to understand JavaScript behavior, not to judge anyone. #JavaScript #LearnJS #FrontendDevelopment #CodingInterview #TechWithVeera #WebDevelopment
To view or add a comment, sign in
-
-
Most developers don’t struggle with JavaScript. They struggle with this. Same function. Different call. Completely different value. That’s why: Code works in one place Breaks in another And interviews get awkward 😅 In Part 8 of the JavaScript Confusion Series, I break down this into 3 simple rules you’ll never forget. No textbook theory. Just a clean mental model. 👉 Read it here: https://lnkd.in/gvc_nG37 💬 Comment THIS if you’ve ever been confused by it. 🔖 Save it for interviews. 🔁 Share with a developer who still avoids this. #javascript #webdevelopment #frontend #programming #reactjs #learnjavascript
To view or add a comment, sign in
-
While digging into JavaScript quirks, l came across this: console.log([] == ![]); // outputs true!!🤔 At first glance this looks wrong — but it’s actually a good example of how JavaScript handles type coercion. Step by step: ![] becomes false because arrays are truthy So the comparison becomes: [] == false With loose equality (==), JavaScript converts types: • [] → "" • false → 0 • "" → 0 Final comparison: 0 == 0 // true Small examples like this are a reminder that understanding JavaScript’s conversion rules is just as important as writing code. That’s why many developers prefer strict equality (===) — fewer surprises, clearer intent. Always learning something new with JS.
To view or add a comment, sign in
-
🚀 Day 6 – Daily Tech Dose (JavaScript) 💡 Today’s Topic: JavaScript Hoisting Quick Question 👇 What will be the output? console.log(a); var a = 10; ✅ Answer: undefined 🧠 Why? • JavaScript hoists variable declarations (not initializations). • var a is moved to the top, but = 10 stays where it is. • So at console.log(a), a exists but has no value yet → undefined. ⚠️ Try the same with let or const and you’ll get a ReferenceError. 💬 Interview Tip • Hoisting applies to functions too (function declarations are fully hoisted). • Prefer let / const to avoid confusing bugs. ⸻ 🔖 Hashtags #JavaScript #WebDevelopment #Frontend #Programming #CodingInterview #LearnJS #TechDaily #100DaysOfCode #VivekVishwakarma Want Day 7 next? 😄
To view or add a comment, sign in
-
-
Today I learned something that completely changed how I think about JavaScript function arguments. For a long time, I believed: Primitive values → Pass by value Objects/Arrays → Pass by reference But here’s the interesting part: In JavaScript, everything is passed by value. Yes — even objects. When we pass an object into a function, we are not passing the actual object. We pass a copy of the reference (memory address). So technically: Primitive → Copy of value Non-primitive → Copy of reference That small difference explains why: -Changing a primitive inside a function doesn’t affect the original. -Modifying properties of an object does affect the original. -Reassigning the object itself does NOT affect the original. Understanding this cleared up so many confusing bugs for me. Golden Rule: If you mutate → original changes If you reassign → original does not change Sometimes growth in coding isn’t about learning something new —it’s about correcting what you thought you already knew. #JavaScript #WebDevelopment #Learning #FrontendDeveloper #Functions
To view or add a comment, sign in
-
-
JavaScript surprise of the day 👇 "017" == 017 → ❌ false "018" == 018 → ✅ true Why? 🤔 👉 Numbers starting with 0 were historically treated as octal (base-8) in JavaScript. 👉 017 becomes 15 (octal → decimal). 👉 "017" (string) converts to 17. So comparison becomes: 17 == 15 → ❌ false But 018 cannot be octal (because 8 isn’t allowed in base-8). 👉 JavaScript treats it as normal decimal 18. 👉 "018" converts to 18. Now: 18 == 18 → ✅ true Moral of the story: JavaScript doesn’t confuse developers… it trains them 😄 #JavaScript #WebDevelopment #Coding #DeveloperHumor #LearningInPublic
To view or add a comment, sign in
-
-
𝗪𝗲𝗹𝗰𝗼𝗺𝗲 𝘁𝗼 𝗗𝗮𝘆 𝟴 Have you ever seen JavaScript behave correctly… but still give the wrong output? 🤔 𝘉𝘦𝘧𝘰𝘳𝘦 𝘴𝘤𝘳𝘰𝘭𝘭𝘪𝘯𝘨, 𝘨𝘶𝘦𝘴𝘴 𝘵𝘩𝘦 𝘰𝘶𝘵𝘱𝘶𝘵 𝘰𝘧 𝘵𝘩𝘪𝘴 𝘴𝘪𝘮𝘱𝘭𝘦 𝘤𝘰𝘥𝘦 𝚏𝚘𝚛 (𝚟𝚊𝚛 𝚒 = 𝟷; 𝚒 <= 𝟹; 𝚒++) { 𝚜𝚎𝚝𝚃𝚒𝚖𝚎𝚘𝚞𝚝(() => { 𝚌𝚘𝚗𝚜𝚘𝚕𝚎.𝚕𝚘𝚐(𝚒); }, 𝟷𝟶𝟶𝟶); } 𝗘𝘅𝗽𝗹𝗲𝗰𝘁𝗲𝗱 1, 2, 3 𝗔𝗰𝘁𝘂𝗮𝗹𝗹𝘆 𝗿𝗲𝘀𝘂𝗹𝘁 4,4,4 𝗧𝗵𝗶𝘀 𝗶𝘀 𝗮 𝗰𝗹𝗼𝘀𝘂𝗿𝗲 𝗯𝘂𝗴 — 𝗼𝗻𝗲 𝗼𝗳 𝘁𝗵𝗲 𝗺𝗼𝘀𝘁 𝗰𝗼𝗺𝗺𝗼𝗻 (𝗮𝗻𝗱 𝗰𝗼𝗻𝗳𝘂𝘀𝗶𝗻𝗴) 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗽𝗶𝘁𝗳𝗮𝗹𝗹𝘀. 𝗪𝗵𝘆 𝗧𝗵𝗶𝘀 𝗛𝗮𝗽𝗽𝗲𝗻𝘀 • var is function-scoped • setTimeout creates a closure • All callbacks reference the same variable i • When they execute, the loop has already finished Closures don’t capture values — they capture references. 𝗧𝗵𝗲 𝗙𝗶𝘅 𝚏𝚘𝚛 (𝚕𝚎𝚝 𝚒 = 𝟷; 𝚒 <= 𝟹; 𝚒++) { 𝚜𝚎𝚝𝚃𝚒𝚖𝚎𝚘𝚞𝚝(() => { 𝚌𝚘𝚗𝚜𝚘𝚕𝚎.𝚕𝚘𝚐(𝚒); }, 𝟷𝟶𝟶𝟶); } 𝗪𝗵𝘆 𝘁𝗵𝗶𝘀 𝘄𝗼𝗿𝗸𝘀: • let is block-scoped • Each iteration gets its own binding • Each closure remembers a different i 𝗬𝗼𝘂’𝗹𝗹 𝘀𝗲𝗲 𝘁𝗵𝗶𝘀 𝗽𝗮𝘁𝘁𝗲𝗿𝗻 𝗶𝗻: • Event handlers • Async loops • API callbacks • Timers • React effects If you don’t understand closures, You don’t see the bug — you just debug longer. #JavaScript #JSFundamentals #Closures #FrontendDevelopment #WebDevelopment #BugFixing #ReactJS #LearningInPublic
To view or add a comment, sign in
-
-
🔄 Understanding the sort() Method in JavaScript Sorting is one of the most common operations in programming — whether you're organizing user data, ranking products, or displaying results. JavaScript provides a built-in sort() method that makes this task simple and efficient. 💡 What is sort()? The sort() method is used to arrange elements of an array in place, meaning it modifies the original array. ⚠️ Key Things Every Developer Should Know ✅ sort() mutates the original array ✅ Default sorting treats elements as strings ✅ Always use a compare function for numbers ✅ Efficient for quick data organization 🎯 When Should You Use sort()? 🔹 Displaying ranked data 🔹 Ordering prices or scores 🔹 Alphabetizing lists 🔹 Preparing structured UI data The real power of sort() lies in the compare function — once you master it, you can sort almost anything in JavaScript. #JavaScript #WebDevelopment #Frontend #CodingTips #LearnJavaScript #SoftwareDevelopment
To view or add a comment, sign in
-
-
🚨 JavaScript Closures: A Tiny Detail, A Big Source of Bugs Sometimes JavaScript doesn’t fail because code is wrong. It fails because our mental model of scope is wrong. 🧠 Closures don’t capture values. They capture references. Because var is function-scoped, every callback shares the same binding. Result? Expected: 0, 1, 2 Actual: 3, 3, 3 No errors. No warnings. Just perfectly valid — yet misleading — behavior. ✅ Two reliable fixes • Explicit scope (closure pattern) • Block scope with let (preferred) 🎯 Why this still matters Closure-related issues quietly surface in: • Async logic • Event handlers • React hooks • Deferred execution • State management patterns These bugs rarely crash. They silently produce wrong behavior. 💡 Takeaway Closures aren’t an academic concept. They’re fundamental to writing predictable JavaScript. #JavaScript #FrontendDevelopment #WebDevelopment #SoftwareEngineering #CleanCode #ReactJS #Closures
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development
Loose and strict equality checks