🧠 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭 𝐓𝐲𝐩𝐞 𝐂𝐨𝐞𝐫𝐜𝐢𝐨𝐧 – 𝐓𝐡𝐞 𝐑𝐞𝐚𝐥 𝐈𝐧𝐭𝐞𝐫𝐯𝐢𝐞𝐰 𝐓𝐫𝐚𝐩 🚀 console.log([] + []); // "" console.log([] + {}); // "[object Object]" console.log({} + []); // "[object Object]" console.log(true + true); // 2 console.log("5" - 2); // 3 console.log("5" + 2); // "52" console.log(2 + "5"); // "25" console.log([1, 2] + [3, 4]); // "1,23,4" console.log(typeof NaN); // "number" console.log(1 < 2 < 3); // true let a; a++; console.log(a); // NaN 💡 What’s happening? + → string concatenation if any operand is string - → converts values to number Arrays/Objects → converted to strings true → 1, false → 0 NaN is still a number type ⚡ Tricky part: 1 < 2 < 3 → true < 3 → 1 < 3 → true 👉 JavaScript doesn’t behave randomly — it follows type coercion rules 🔥 Master this = Crack any frontend interview #JavaScript #FrontendDeveloper #TypeCoercion #CodingInterview #WebDevelopment #TechTips #LearnToCode #ReactJS #Hiring #FrontendRecruiter
JavaScript Type Coercion Interview Trick
More Relevant Posts
-
🚀 The #1 Most Asked Angular Interview Question: "What's the difference between switchMap, mergeMap, concatMap, and exhaustMap?" 🤔 If you've ever mapped an HTTP request inside an RxJS stream and ended up with an `Observable<Observable<Data>>`, you've hit the Higher-Order Observable Nightmare! Understanding these 4 Concurrency Operators separates the junior developers from the Senior Engineers. Here is my ultimate visual cheat sheet: 1️⃣ switchMap (The Canceller) 🔪 - Perfect for search inputs. It instantly cancels old, pending requests. 2️⃣ mergeMap (The Multi-Tasker) 🚀 - Perfect for firing off parallel requests where order doesn't matter. 3️⃣ concatMap (The Queuer) ⏳ - Perfect for strict, step-by-step sequential API calls. 4️⃣ exhaustMap (The Ignorer) 🛑 - Perfect for "Pay Now" buttons to completely ignore spam clicks! Swipe through the carousel 👇 for full visual marble diagrams and code examples of each! Which operator do you end up using the most? Let me know in the comments! 👇 #Angular #RxJS #WebDevelopment #Frontend #JavaScript #TechTips #SoftwareEngineering #AbidAnsari
To view or add a comment, sign in
-
Why does this return true… but this returns false? 🤔 const obj = { 1: 'a', 2: 'b', 3: 'c' }; const set = new Set([1, 2, 3, 4, 5]); obj.hasOwnProperty('1'); // true obj.hasOwnProperty(1); // true set.has('1'); // false set.has(1); // true Here’s the catch 👇 👉 Objects convert keys to strings 👉 Sets use strict equality (===) So: 1 → '1' (in objects) ✅ '1' !== 1 (in sets) ❌ 💡 Objects coerce. Sets don’t. Did you know this before? Follow for more bite-sized JavaScript insights 🚀 #javascript #software engineering #frontend development
To view or add a comment, sign in
-
[ Here's what you need to know about the JavaScript Event Loop ] Most JavaScript developers use async code every day. But if you ask them what actually happens under the hood... silence. JavaScript is single-threaded. It does ONE thing at a time. Yet it handles async operations without freezing the entire page. Uhkay... BUT, How? The Event Loop existence is the guy behind it. There are 4 layers you need to understand: 1 - Call Stack Where your code actually executes — one line at a time. It only receives things that are ALREADY resolved and ready to run. 2 - Web APIs Where async tasks go to wait. setTimeout, fetch, event listeners — they all leave the Call Stack and sit here while they process. 3 - Callback Queue When a Web API task finishes, it pushes its callback here. The Event Loop picks it up only when the Call Stack is empty. 4 - Microtask Queue Same idea — but for Promises. And it has HIGHER priority than the Callback Queue. The order of execution is always: Call Stack → Microtask Queue (Promises) → Callback Queue (setTimeout, etc.) This is why this code might surprise you: console.log("1"); setTimeout(() => console.log("2"), 0); Promise.resolve().then(() => console.log("3")); console.log("4"); // Output: 1, 4, 3, 2 Even with 0ms delay, setTimeout runs LAST. Because it goes through the Callback Queue — and Promises (Microtask Queue) always go first. The key insight interviewers love to hear: "When a callback finally reaches the Call Stack, the work is already done. The Web API handled the heavy lifting. The Call Stack only receives results — never waiting tasks." This is one of the most asked JavaScript fundamentals in technical interviews. And most candidates get it half right. #javascript #webdevelopment #frontend #programming #technicalinterview
To view or add a comment, sign in
-
𝗜𝗳 𝘆𝗼𝘂 𝗮𝗿𝗲 𝗰𝗹𝗲𝗮𝗿 𝗮𝗯𝗼𝘂𝘁 𝘁𝗵𝗲𝘀𝗲 𝟯𝟬 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗰𝗼𝗻𝗰𝗲𝗽𝘁𝘀, 𝘆𝗼𝘂 𝘄𝗶𝗹𝗹 𝗰𝗹𝗲𝗮𝗿 𝟵𝟬% 𝗼𝗳 𝘁𝗵𝗲 𝗝𝗦 𝗶𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄𝘀. 𝗘𝘅𝗲𝗰𝘂𝘁𝗶𝗼𝗻, 𝗦𝗰𝗼𝗽𝗲 & 𝗠𝗲𝗺𝗼𝗿𝘆 1. Execution context & call stack 2. var, let, const (scope + hoisting + TDZ) 3. Lexical scope & scope chain 4. Closures (behavior, not definition) 5. Shadowing & illegal shadowing 6. Garbage collection basics & memory leaks 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻𝘀 & 𝘁𝗵𝗶𝘀 1. Function declarations vs expressions 2. this binding rules (default, implicit, explicit, new) 3. call, apply, bind 4. Arrow functions vs normal functions 5. Currying & partial application 6. Higher-order functions 𝗔𝘀𝘆𝗻𝗰 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 (𝗵𝗶𝗴𝗵𝗲𝘀𝘁 𝗿𝗲𝗷𝗲𝗰𝘁𝗶𝗼𝗻 𝗮𝗿𝗲𝗮) 1. Event loop (call stack, microtasks, task queue) 2. Promises & chaining 3. async / await (error handling & sequencing) 4. Race conditions & stale closures 5. Timers (setTimeout, setInterval) vs microtasks 6. Promise utilities (all, allSettled, race, any) 𝗗𝗮𝘁𝗮, 𝗥𝗲𝗳𝗲𝗿𝗲𝗻𝗰𝗲𝘀 & 𝗘𝗦𝟲+ 1. == vs ===, truthy / falsy values 2. Object & array reference behavior 3. Deep vs shallow copy 4. Destructuring, rest & spread 5. Map, Set, WeakMap, WeakSet (why they exist) 𝗕𝗿𝗼𝘄𝘀𝗲𝗿 & 𝗥𝘂𝗻𝘁𝗶𝗺𝗲 𝗙𝘂𝗻𝗱𝗮𝗺𝗲𝗻𝘁𝗮𝗹𝘀 (𝗳𝗿𝗼𝗻𝘁𝗲𝗻𝗱 𝗱𝗶𝗳𝗳𝗲𝗿𝗲𝗻𝘁𝗶𝗮𝘁𝗼𝗿𝘀) 1. Event bubbling, capturing & target phase 2. Event delegation (why it works, when it fails) 3. preventDefault() vs stopPropagation() 4. DOM vs Virtual DOM (conceptual difference) 5. Reflow vs repaint (what triggers each) 6. Web storage (localStorage, sessionStorage, cookies) 7. What can and cannot be polyfilled (and why) #frontend #javascript #reactjs #interviewpreparation #frontenddeveloper #webdevelopment #career #angularDeveloper #angular
To view or add a comment, sign in
-
👉 Data Binding — the bridge between your UI & logic 💡 Simple idea: Your component (TypeScript) ↔ Your template (HTML) Both stay in sync automatically 🧠 What’s really happening? • Data flows from component → UI (Interpolation / Property Binding) • User actions flow from UI → component (Event Binding) • Two-way binding syncs both sides instantly 👉 That’s what makes Angular apps dynamic 🔥 The 4 core types: • {{ }} Interpolation → Display data • [ ] Property Binding → Set element properties • ( ) Event Binding → Handle user actions • [( )] Two-Way Binding → Real-time sync ⚠️ Where things go wrong: Overusing two-way binding everywhere 👇 💥 Performance issues in large apps 🎯 Why this matters: ✔ Cleaner and maintainable code ✔ Better performance decisions ✔ Strong Angular fundamentals ✔ Helps in real-world projects & interviews #Angular #WebDevelopment #Frontend #JavaScript #Coding #Developers #LearnInPublic
To view or add a comment, sign in
-
-
𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗧𝘆𝗽𝗲 𝗖𝗼𝗻𝘃𝗲𝗿𝘀𝗶𝗼𝗻 𝗹𝗼𝗼𝗸𝘀 𝘀𝗶𝗺𝗽𝗹𝗲… 𝘂𝗻𝘁𝗶𝗹 𝗧𝗛𝗜𝗦 𝗵𝗮𝗽𝗽𝗲𝗻𝘀 😵 𝗢𝗻𝗲 𝗹𝗶𝗻𝗲 𝗼𝗳 𝗰𝗼𝗱𝗲 𝗰𝗮𝗻 𝗰𝗼𝗺𝗽𝗹𝗲𝘁𝗲𝗹𝘆 𝗰𝗵𝗮𝗻𝗴𝗲 𝘆𝗼𝘂𝗿 𝗹𝗼𝗴𝗶𝗰 👇 Example: 𝑐𝑜𝑛𝑠𝑜𝑙𝑒.𝑙𝑜𝑔("5" + 2); 𝑐𝑜𝑛𝑠𝑜𝑙𝑒.𝑙𝑜𝑔("5" - 2); 🤔 What will be the output? A) 7 and 3 B) "52" and 3 C) "52" and "3" D) Error 👇 Take a guess before scrolling! . . . . . . . . . . . . ✅ Correct Answer: "52" and 3 Surprised? Let’s break it down 👇 💡 𝗪𝗵𝗮𝘁’𝘀 𝗵𝗮𝗽𝗽𝗲𝗻𝗶𝗻𝗴? JavaScript does 𝗧𝘆𝗽𝗲 𝗖𝗼𝗻𝘃𝗲𝗿𝘀𝗶𝗼𝗻 (𝗖𝗼𝗲𝗿𝗰𝗶𝗼𝗻) automatically when different data types interact. 👉 "5" + 2 ◦ + operator prefers string concatenation ◦ Number 2 gets converted to "2" ◦ Result → "52" 👉 "5" - 2 ◦ - operator works only with numbers ◦ "5" gets converted to 5 ◦ Result → 3 🚀 𝗦𝗶𝗺𝗽𝗹𝗲 𝗘𝘅𝗽𝗹𝗮𝗻𝗮𝘁𝗶𝗼𝗻: ◦ JavaScript tries to be “smart” (sometimes too smart 😅) ◦ It converts types behind the scenes based on the operator ◦ + → can mean addition OR concatenation ◦ Other operators (-, *, /) → force numbers 🔑 𝗞𝗲𝘆 𝗧𝗮𝗸𝗲𝗮𝘄𝗮𝘆𝘀: • "5" + 2 → string conversion (concatenation) • "5" - 2 → number conversion (math operation) • Always be careful when mixing data types 🔥 𝗗𝗶𝗱 𝘆𝗼𝘂 𝗴𝗲𝘁 𝗶𝘁 𝗿𝗶𝗴𝗵𝘁? 𝗢𝗿 𝗱𝗶𝗱 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝘁𝗿𝗶𝗰𝗸 𝘆𝗼𝘂 𝗮𝗴𝗮𝗶𝗻? Drop your answer 👇 And save this — this concept causes real bugs in production 🚀 💡 Part of #FrontendRevisionMarathon — breaking down Frontend concepts daily 🚀 🚀 Follow Shubham Kumar Raj for more such content. #JavaScript #WebDevelopment #Frontend #CodingTips #100DaysOfCode #codinginterview #learnjavascript #programming #interviewprep #CareerGrowth #SowftwareEngineering #OpenToWork #ReactJS #FrontendDevelopment #Coding #Hiring
To view or add a comment, sign in
-
-
🚀 Day 2/30 — React Machine Coding Challenge Build a Multi-Step Registration Wizard with: - 3–4 steps (Basic Info, Address, Preferences, Review) - “Next” only when current step is valid - Back/Next navigation without losing data - Final review screen before submit 🧠 Before you scroll… How would you design this? - Where will you store the form state — per step or globally? - How will you validate each step before moving forward? - How do you prevent data loss when navigating back? 💡 My Approach: - Keep a single source of truth for all form data - Track current step with a simple state - Add step-based validation before allowing “Next” - Keep step components dumb (just UI + inputs) Now your turn 👇 Try solving this and share your approach/code in the comments. I’ll review and give feedback. If you're preparing for frontend interviews, follow along — new challenge every day. #30DaysOfCode #ReactJS #MachineCoding #FrontendDevelopment #InterviewPrep #BuildInPublic #JavaScript
To view or add a comment, sign in
-
🚀 JavaScript Tricky Question — Can you predict the output? console.log(a); var a = 10; function test() { console.log(a); var a = 20; } test(); 🧠 What will be the output? Most developers expect: 10 20 But the actual output is: undefined undefined ✅ Why does this happen? This is due to hoisting in JavaScript. var declarations are hoisted to the top But their values are not initialized immediately So the variable exists, but its value is undefined Behind the scenes, JavaScript interprets it like this: var a; console.log(a); // undefined a = 10; function test() { var a; console.log(a); // undefined a = 20; } Real-world takeaway Understanding hoisting is critical when: * Debugging unexpected undefined values * Working with legacy JavaScript code * Preparing for frontend interviews * Writing predictable, maintainable code 💡 My learning lesson: Always declare variables at the top of the scope and prefer let / const over var to avoid hoisting-related bugs. #FrontendDeveloper #JavaScript #ReactJS #WebDevelopment #FrontendInterview #Coding #SoftwareEngineering #TechLearning #hiringFrontend
To view or add a comment, sign in
-
🚀 JavaScript Event Loop — Explained Simply (with Example) If you’re preparing for frontend interviews or working with async JS, understanding the Event Loop is a must! 💯 🧠 What is Event Loop? 👉 JavaScript is single-threaded, but still handles async tasks like a pro 👉 Event Loop ensures non-blocking execution by managing execution order ⚙️ Key Concepts: 📌 Call Stack → Executes synchronous code 📌 Web APIs → Handles async tasks (setTimeout, fetch, DOM events) 📌 Microtask Queue → Promises (high priority ⚡) 📌 Callback Queue → setTimeout, setInterval 🔥 Example: JavaScript console.log("Start"); setTimeout(() => { console.log("Timeout"); }, 0); Promise.resolve().then(() => { console.log("Promise"); }); console.log("End"); 🎯 Output: Start End Promise Timeout 🧩 Why this output? 👉 JS executes sync code first 👉 Then Event Loop checks: ✔ Microtasks (Promises) → First ✔ Macrotasks (setTimeout) → After 💡 Golden Rule: 👉 Promise > setTimeout (Priority matters!) 🚀 Real-world usage: ✔ API calls (fetch/axios) ✔ UI updates without blocking ✔ Handling async flows in React apps 🎯 Interview One-liner: 👉 “Event Loop manages async execution by prioritizing microtasks over macrotasks after the call stack is empty.” If this helped you, drop a 👍 or comment below! Let’s keep learning and growing 🚀 #JavaScript #EventLoop #FrontendDevelopment #ReactJS #WebDevelopment #CodingInterview #AsyncJS #Developers
To view or add a comment, sign in
-
Most developers struggle with closures & this… Not because they’re hard — but because they’re misunderstood 👀 👉 Once you truly get these two concepts, JavaScript stops feeling confusing… and starts feeling predictable. This post breaks it down simply: • Closures → How functions remember their scope even after execution • Data Privacy → Real-world use (like hiding variables) • Function Factories & Memoization → Performance + reusable logic • this Keyword → Not where it’s written, but how it’s called • Arrow Functions → Lexical this (no own binding) • call / apply / bind → Full control over execution context • Execution Context → What actually happens behind the scenes 📌 One powerful idea: A function doesn’t just run… it carries its environment with it If you understand this deeply: You don’t debug blindly anymore — you predict behavior ⚡ Save this. This is one of the most asked (and misunderstood) topics in JS interviews. #JavaScript #FrontendDevelopment #WebDevelopment #JSConcepts #Closures #ThisKeyword #CallApplyBind #ExecutionContext #InterviewPrep #ReactJS #SoftwareEngineering #CodingInterview #LearnJavaScript #Developers #TechContent
To view or add a comment, sign in
Explore related topics
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
👉 1 < 2 < 3 → true < 3 → 1 < 3 → true 1 < 2 → true true → converted to 1 1 < 3 → true 👉 JavaScript converts boolean → number, which makes this expression tricky! 👉 let a; a++ → undefined → NaN → result is NaN a starts as undefined a++ tries to convert it to a number → becomes NaN 👉 Any operation with undefined in numeric context results in NaN