Ever tried reading a property that doesn’t exist in JavaScript? No crash. No error. Just… undefined 😄 Most of us do this: if (user.noSuchProperty === undefined) { ... } Works 99% of the time. Until it doesn’t. let obj = { test: undefined }; console.log(obj.test); // undefined console.log("test" in obj); // true ← surprise! The property exists — it just happens to hold undefined. That tiny difference is exactly why the in operator exists. Have you ever been bitten by this gotcha? Or do you still prefer === undefined in everyday code? #JavaScript #CodingTips #WebDevelopment
JavaScript Property Gotcha: The 'in' Operator
More Relevant Posts
-
🧠 What is Hoisting? (Explained Simply) JavaScript moves declarations to the top. Example: console.log(a); var a = 5; Output? 👉 undefined Because: JS reads it as: var a; console.log(a); a = 5; Important: var → hoisted with undefined let & const → hoisted but in Temporal Dead Zone Have you ever faced hoisting confusion? 😅 #JavaScript #JSConcepts #Learning
To view or add a comment, sign in
-
-
📊 Day 6 - poll answer and explanation console.log(0 || "Hello"); console.log("Hello" || 0); Rule of || in JavaScript (Important ⭐) 👉 It evaluates left to right 👉 It returns the first truthy value 👉 If all values are falsy, it returns the last value These are falsy values in JavaScript false, 0, "", null, undefined, NaN 🎯 Final output "Hello" "Hello" Hope this explanation is helpful😊 #JavaScript #JavaScriptTricks #LogicalOperators #JavaScriptInterview #FrontendDevelopment #WebDevelopment #CodingConcepts #LearnJavaScript #DeveloperCommunity #30DaysOfJavaScript #100DaysOfCode #TechCommunity #DailyLearning
To view or add a comment, sign in
-
JavaScript is single-threaded, but async code doesn’t just run whenever it feels like it. The engine processes: The call stack Then microtasks (Promises) Then macrotasks (setTimeout, etc.) Which means this: console.log("Start"); setTimeout(() => console.log("Timeout"), 0); Promise.resolve().then(() => console.log("Promise")); console.log("End"); Logs: Start End Promise Timeout Even with 0ms, setTimeout waits until the microtask queue is empty. Once I understood that, async bugs stopped feeling random. The event loop isn’t just trivia, it’s how you reason about timing instead of guessing. #JavaScript #EventLoop #AsyncProgramming #WebDevelopment
To view or add a comment, sign in
-
learned about the switch statement in JavaScript. It is used when we need to check multiple conditions. Example: let day = 2; switch(day){ case 1: console.log("Monday"); break; case 2: console.log("Tuesday"); break; default: console.log("Another day"); } Switch statements make code cleaner when handling many conditions. #JavaScript #CodingJourney #FrontendDeveloper
To view or add a comment, sign in
-
-
📊 Yesterday poll answer and explanation - Day 5 console.log(0 && "Hello"); console.log("Hello" && 0) Rule of && in JavaScript (Important ⭐) 👉 It evaluates left to right 👉 It returns the first falsy value, 👉 If no falsy value is found, it returns the last truthy value These are falsy values in JavaScript false, 0, "", null, undefined, NaN 🎯 Final output 0, 0 Hope this explanation is helpful😊 #JavaScript #FrontendDeveloper #WebDevelopment #LearningJavaScript #InterviewPrep
To view or add a comment, sign in
-
A classic JavaScript trap 🧠 What will this log? const values = [ 1, 1, true, false, 0, '', {}, [] ]; console.log( values.filter( parseInt ) ); console.log( values.filter( Boolean ) ); For the first log, is it [1, 1]? Or something else? What about the second one? Think first. Then run it. The result is not what most people expect 😄 #JavaScript #CodingChallenge #WebDevelopment
To view or add a comment, sign in
-
-
JavaScript question 🧠 What will this log? Think before running it. const values = [ 0, -0, +0 ]; const set = new Set( values ); console.log( set.size ); A) 1 B) 2 C) 3 Are 0, -0, and +0 treated as different values? Or does Set see them as the same? #JavaScript #CodingChallenge #Frontend
To view or add a comment, sign in
-
-
🔥 JavaScript Concept: Hoisting — Code Moves Before Execution Hoisting is JavaScript’s behavior of moving declarations to the top of their scope before execution. 🔹 Key Points ✔ "var" is hoisted and initialized as "undefined" ✔ "let" & "const" are hoisted but NOT initialized (Temporal Dead Zone) ✔ Function declarations are fully hoisted 🔹 Example console.log(a); // undefined var a = 10; console.log(b); // Error let b = 20; 💡 Understanding hoisting helps prevent unexpected bugs. Write predictable code → Prefer "let" and "const" ✔ #JavaScript #Hoisting #CleanCode #Developers
To view or add a comment, sign in
-
🎮 Built a Mini JavaScript Game – Catch the Cheese After learning basics, I challenged myself to build a small game using pure HTML, CSS & JavaScript. 🧠 Concepts I applied: • Game logic • Event listeners • Score tracking • Timers This project improved my problem-solving skills and logical thinking. GitHub: https://lnkd.in/dfSfNZCd Live demo: https://lnkd.in/d6R2zGv5 #JavaScript #FrontendDeveloper #CodingJourney
To view or add a comment, sign in
-
🚀 30 Days of JavaScript Tricky Questions – Day 1 Let’s start with async / await + event loop 🧠 async function foo() { console.log('A'); setTimeout(() => console.log('B'), 0); await Promise.resolve(); console.log('C'); } foo(); console.log('D'); ❓ What will be the output and why? 💬 Drop your answer in the comments #JavaScript #JSInterview #AsyncJavaScript #FrontendDeveloper #WebDevelopment #30DaysOfJavaScript
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