🚀 Day 18 - Poll answer & Explanation || vs ?? — Small difference, big impact ⚡ const a = 0; const b = 0; console.log(a || 'default'); // 'default' console.log(a ?? 'default'); // 0 const config = { timeout: 0 }; console.log(config.timeout || 5000); // 5000 console.log(config.timeout ?? 5000); // 0 Explanation: || (OR operator): - Returns the first "truthy" value - 0 is falsy → so it picks 'default' or 5000 ?? (Nullish Coalescing): - Returns the right side ONLY if value is null or undefined - 0 is NOT null/undefined → so it keeps 0 Key Difference: || treats 0, "", false as falsy ?? treats only null and undefined as empty Use ?? when 0 or false are valid values #JavaScript #WebDevelopment #Frontend #Coding #100DaysOfCode #JSConcepts #LearnToCode #Programming #Developer #CodeNewbie
JavaScript OR vs Nullish Coalescing Explained
More Relevant Posts
-
Here is the golden rule: Use .forEach() when you want to DO something. (Like logging to the console or pushing to an external array). It returns undefined. Use .map() when you want to CREATE something new. It returns a brand new array of the same length. JavaScript const numbers = [1, 2, 3]; // ❌ Bad: Using map just to loop (creates an unused array in memory) numbers.map(num => console.log(num)); // ✅ Good: Using map in React to create an array of JSX elements const UI = numbers.map(num => <li key={num}>{num}</li>); Understanding this difference is crucial for writing clean, bug-free components! #JavaScript #ReactJS #CodingLife #WebDevelopment #Programming #LearnToCode
To view or add a comment, sign in
-
-
🚀 Day 25 - Poll answer & Explanation console.log("S"); setTimeout(() => console.log("T"), 0); async function t() { console.log("AS"); await null; console.log("AE"); } t(); console.log("E"); /* ✨ Output: S AS E AE T 🧠 Explanation: 1️⃣ console.log("S") 👉 Runs immediately (synchronous) 2️⃣ setTimeout(..., 0) 👉 Goes to macrotask queue ⏳ (runs later) 3️⃣ t() is called 👉 "AS" runs immediately (sync inside async) 4️⃣ await null 👉 Pauses function ⏸️ 👉 "AE" moves to microtask queue ⚡ 5️⃣ console.log("E") 👉 Runs next (still synchronous) 6️⃣ Microtask queue runs ⚡ 👉 "AE" 7️⃣ Macrotask queue runs ⏳ 👉 "T" 📌 Final Order: Synchronous → Microtask → Macrotask */ #JavaScript #JS #WebDevelopment #Frontend #Programming #Coding #CodeChallenge #Tech #Developers #LearnJavaScript #CodingTips #DevCommunity #100DaysOfCode #CodeNewbie #SoftwareDevelopment #TechTrends #InterviewPrep #DailyCoding
To view or add a comment, sign in
-
🔥 Let’s talk about something we all “know”… but rarely truly understand: The JavaScript Event Loop. Quick question 👇 Have you ever written async code… but your app still felt blocked? 👉 Here’s why: JavaScript runs on a single thread. So if you do this: while(true) {} 💥 Everything stops: UI freezes Promises don’t resolve API calls get delayed 💡 The reality: Async helps with I/O… not CPU work. ⚡ What changed my thinking: “If the main thread is busy, nothing else matters.” 👉 What I do now: ✔ Break heavy tasks into chunks ✔ Avoid long synchronous loops ✔ Use workers when needed Once you truly understand the event loop… debugging becomes 10x easier. What was your biggest “event loop moment”? 😄 #javascript #eventloop #webdevelopment #performance #programming #frontend #backend #softwareengineering #Coding #TechCareers
To view or add a comment, sign in
-
-
𝐋𝐞𝐬𝐬𝐨𝐧 𝐥𝐞𝐚𝐫𝐧𝐞𝐝 - 1 Why should we commit the package-lock.json file to our repository? 🤔 1. What is the problem? My pet project was running smoothly during development. But after deployment, the same code suddenly started failing when I ran it on another system even though I hadn’t changed anything. 2. How did I solve it? After that I started committing package-lock.json to the repo. This file locks every package to an exact version. So every install, everywhere, produces the same result. No more surprise breaks. 3. Have you faced this? How did you handle it? Share in the comments 👇 #frontend #javascript #webdevelopment #debugging #learning
To view or add a comment, sign in
-
JavaScript is single threaded, but handles async operations so smoothly 👇 That’s where the Event Loop comes in. At first, things seem simple: • Code runs line by line But then you see behavior like this: Even with 0ms, the timeout doesn’t run immediately. Because JavaScript uses: ✔ Call Stack ✔ Web APIs ✔ Callback Queue ✔ Event Loop Understanding this changed how I think about async code and debugging. Sometimes the delay isn’t about time, it’s about how the event loop schedules execution. #JavaScript #EventLoop #AsyncJavaScript #FrontendDevelopment #Programming
To view or add a comment, sign in
-
-
🚀 You use JavaScript every day… But do you know what’s happening under the hood? 👉 Meet the V8 Engine ⚡ — the real reason your JS is FAST. 🔥 5 Insanely Interesting V8 Features Developers Should Know ⚡ 1. JIT (Just-In-Time) Compilation V8 doesn’t just read your code… 👉 It converts it into machine code instantly for speed. 🧠 2. Hidden Classes (Yes, JS has them!) JavaScript is dynamic… but V8 makes it behave like a static language internally. 👉 This boosts performance BIG TIME. 🚀 3. Inline Caching V8 remembers how your code runs frequently. 👉 Reuses optimized paths instead of recalculating. 🧹 4. Smart Garbage Collection Automatic memory cleanup 👉 Keeps your app fast & memory-efficient 🔄 5. Event Loop + Async Magic (via Node.js) Handles thousands of requests without blocking 👉 Perfect for real-time apps 💡 Bonus Insight: Your code performance depends on how “V8-friendly” it is 👀 ✔ Avoid unnecessary object shape changes ✔ Use consistent data structures ✔ Don’t overcomplicate loops 🔥 Reality Check: Frameworks don’t make JavaScript fast… 👉 The engine does. 💬 What surprised you the most about V8? Let’s discuss 👇 #JavaScript #NodeJS #V8 #WebPerformance #Coding #Developers #Tech #SoftwareEngineering #Programming #Backend #Frontend
To view or add a comment, sign in
-
-
JavaScript Array Trick (Most Devs Miss This!) Problem: let arr = [1, 2, 3, 4, 5]; arr[10] = 42; console.log(arr); console.log(arr.length); What will be the output? #javascript #mern #webdevelopment #coding #developer
To view or add a comment, sign in
-
🚀 Day 22 - Poll answer & Explanation const map = new Map(); map.set("a", 1); map.set("b", 2); const set = new Set([1, 2, 3, 3]); console.log(map.size, set.size); 2 3 Explanation (simple & clear): - Map stores key-value pairs → "a" and "b" → size = 2 - Set stores only unique values → duplicates removed - [1, 2, 3, 3] → becomes [1, 2, 3] → size = 3 Key Point: - Map counts unique keys - Set automatically removes duplicate values Output: 2 3 #JavaScript #JSInterview #FrontendDevelopment #WebDevelopment #CodingChallenge #JSConcepts #Developers #Programming #TechInterview #LearnJavaScript #100DaysOfCode #CodeNewbie #SoftwareDevelopment #CodingTips #JSBasics #DevelopersLife
To view or add a comment, sign in
-
How TypeScript Compiles Your Code – Step by Step! Ever wondered what happens behind the scenes when you run tsc? TypeScript does a lot more than just adding types to JavaScript. It has a 5-stage compiler workflow that ensures your code is safe, structured, and ready to run. In this carousel, we’ll break down each stage: 1️⃣ Lexer – Converts your code into tokens 2️⃣ Parser – Builds the Abstract Syntax Tree (AST) 3️⃣ Binder – Tracks symbols, scopes, and flow nodes 4️⃣ Checker – Performs syntax and type checking 5️⃣ Emitter – Generates .js, .d.ts, and .map files Swipe through to see each stage visually, understand how TypeScript works under the hood, and get a glimpse of why it’s so powerful for developers! 💻 #TypeScript #WebDevelopment #Frontend #Programming #Developers #CodingTips #JavaScript
To view or add a comment, sign in
-
Ever wondered why JavaScript shows “undefined” even before a variable is assigned? 🤯 console.log(a); var a = 10; At first glance, this feels confusing… But the answer lies in one powerful concept: 👉 Execution Context Here’s what actually happens behind the scenes: ⚡ When JavaScript runs your code, it creates an Execution Context ⚡ In the memory phase, variables are hoisted → initialized as undefined ⚡ In the execution phase, code runs line by line and values get assigned I made a short video explaining the basics—would love your feedback 🙌 #javascript #webdevelopment #frontend #programming #coding #developers #learntocode #100daysofcode
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