🚀 Day 22/100 – #100DaysOfCode JavaScript Interview Questions (Core Concepts) Revised some fundamental JavaScript interview questions that every developer is expected to understand clearly. 🔹 Primitive vs Non-Primitive Data Types -Primitive: Stored by value (Number, String, Boolean, Null, Undefined, Symbol, BigInt) -Non-Primitive: Stored by reference (Object, Array, Function) Primitive types are immutable, while non-primitives are mutable. 🔹 Truthy vs Falsy Values -Falsy values: false, 0, "", null, undefined, NaN -Truthy values: Everything else (e.g., "hello", 1, [], {}) Used heavily in conditions like if statements. 🔹 null vs undefined undefined: A variable is declared but not assigned a value null: Intentionally assigned empty value undefined = default, null = intentional absence 🔹 == vs === (Double vs Triple Equal) == → Compares value only (type coercion happens) === → Compares value and type (strict comparison) Always prefer === to avoid unexpected bugs. 🔹 Scope in JavaScript Scope determines where variables are accessible: -Global Scope → Accessible everywhere -Function Scope → Accessible inside functions -Block Scope → Accessible inside {} (let, const) Understanding scope is critical for avoiding bugs and writing predictable code. 22 days down, 78 more to go. #Day22 #100DaysOfCode #JavaScript #FrontendDevelopment #WebDevelopment #CodingInterview
JavaScript Core Concepts: Primitive Types, Truthy/Falsy, Null/Undefined, Equality, Scope
More Relevant Posts
-
🚀 Day 23/100 – #100DaysOfCode JavaScript Interview Questions (Advanced Concepts) Continuing with JavaScript fundamentals, today I reviewed some important interview questions that test a deeper understanding of how JavaScript works under the hood. 🔹 Hoisting Hoisting is JavaScript’s behavior where variable and function declarations are moved to the top of their scope before execution. var is hoisted with undefined, while let and const are hoisted but remain in the temporal dead zone. 🔹 Callback Function A callback is a function passed as an argument to another function, which is executed later. Commonly used in: -Asynchronous operations (API calls) -Event handling 🔹 Closure A closure is a function that remembers variables from its lexical scope even after the outer function has finished execution. This is heavily used in: -Data encapsulation -Maintaining private variables 🔹 Pass by Value vs Pass by Reference Pass by Value: A copy of the value is passed (Primitive types) Pass by Reference: A reference to the original object is passed (Objects, Arrays) Changes in reference types affect the original data, while primitive changes do not. Understanding these concepts is critical because they often separate beginners from intermediate developers in interviews. 23 days down, 77 more to go. #Day23 #100DaysOfCode #JavaScript #FrontendDevelopment #WebDevelopment #CodingInterview #MERN
To view or add a comment, sign in
-
JavaScript Closures: The Interview Question That Separates Juniors from Seniors 🔒 Stop memorizing definitions. Start explaining like a pro. The 30-Second Interview Answer: 📌 Definition A closure is a function that "remembers" its lexical scope even when executed outside that scope. 📌 The Structure ```javascript function outer() { let secret = "private"; return function inner() { return secret; // Closure! }; } const closure = outer(); console.log(closure()); // "private" ``` 📌 Real-World Use Debouncing search inputs – prevents API calls on every keystroke: ```javascript function debounce(fn, delay) { let timer; return (...args) => { clearTimeout(timer); timer = setTimeout(() => fn(...args), delay); }; } // Saves $$$ on API costs! ``` 📌 Why It Matters • Encapsulation – private variables without classes • Performance – debounce/throttle events • State persistence – remembers values across calls 📌 Senior-Level Insight "Closures are powerful but can cause memory leaks if not cleaned up. Always remove event listeners and nullify references when components unmount." The Bottom Line: Closures aren't just theory – they're the foundation of React Hooks, event handlers, and efficient JavaScript. --- 💡 Interview Tip: When asked about closures, always follow with a real-world example. Theory proves you studied. Application proves you code. Found this useful? ♻️ Share with someone preparing for interviews. Follow me for more JavaScript deep dives! #JavaScript #WebDevelopment #CodingInterview #TechCareers #FrontendDeveloper
To view or add a comment, sign in
-
Recently in an interview, I was asked about the JavaScript Event Loop… I thought I knew it — but explaining it clearly was harder than expected. So I created this diagram to understand it properly 👇 • Understanding JavaScript Event Loop (Simple Explanation) ° JavaScript Engine JavaScript runs on a single thread. It uses: • Memory Heap → to store data • Call Stack → to execute code 📞 Call Stack All synchronous code runs here. Functions are pushed and popped one by one. 🌐 Web APIs (Browser / Node.js) Async operations are handled outside the JS engine: • setTimeout / setInterval • fetch API • DOM events These APIs run in the background. 📥 Queues Once async work is done, callbacks go into queues: 👉 Microtask Queue (High Priority) • Promise.then() • async/await 👉 Task Queue (Low Priority) • setTimeout • setInterval • DOM events 🔁 Event Loop (Most Important Part) The event loop keeps checking: Is Call Stack empty? Execute ALL Microtasks Then execute ONE Task from Task Queue That’s why Promises run before setTimeout! One Line Summary: JavaScript uses Call Stack + Web APIs + Queues + Event Loop to handle async code without blocking execution. This is one of the most common interview questions — but also one of the most misunderstood. If you can explain this clearly, you’re already ahead of many developers. #JavaScript #EventLoop #AsyncJavaScript #WebDevelopment #NodeJS #Frontend #Programming #Interview
To view or add a comment, sign in
-
-
ADVANCED JAVASCRIPT CONCEPTS FOR INTERVIEWS #SaveForLater #MohitDecodes If you're preparing for JavaScript interviews, these are must-know concepts that can seriously level up your understanding 👇 -- Callback Function passed as an argument & executed later → leads to callback hell -- Promise Handles async operations → resolve / reject (cleaner than callbacks) -- Async/Await Syntactic sugar over promises → makes async code look synchronous -- Strict Mode ("use strict") Catches silent errors & enforces cleaner coding practices -- Higher Order Functions Functions that take/return other functions → map, filter, reduce -- Call, Apply, Bind Control the value of this → powerful for context handling -- Scope Block | Function | Global → defines variable accessibility -- Closures Access outer function variables even after execution -- Hoisting Variables & functions moved to top before execution -- IIFE Immediately Invoked Functions → avoid global pollution -- Currying Convert multi-arg function → chain of single-arg functions -- Debouncing Delay execution → improves performance (search inputs, etc.) -- Throttling Limit execution rate → useful in scroll/resize events -- Polyfills Add support for modern features in older browsers 💡 These are not just interview questions — they define how JavaScript actually works under the hood. Pro Tip: Don’t just read — implement each concept with code! 💬 Was this helpful? 🔖 Save for later 📢 Follow for more: Mohit Kumar #JavaScript #Frontend #WebDevelopment #ReactJS #InterviewPrep #Coding #100DaysOfCode
To view or add a comment, sign in
-
🚀 Day 4/30 – Frontend Interview Series 🔥 Topic: Closures in JavaScript 💡 What is a Closure? A closure is created when a function “remembers” its outer variables even after the outer function has finished executing. 👉 In simple words: A function + its lexical scope = Closure 🧠 Example: function outerFunction() { let count = 0; return function innerFunction() { count++; console.log(count); }; } const counter = outerFunction(); counter(); // 1 counter(); // 2 counter(); // 3 🔍 Why Closures are Important? ✔ Data hiding / Encapsulation ✔ Used in callbacks ✔ Used in React (hooks internally use closures) ✔ Helps in maintaining state ⚡ Real-world Use Case: function createUser(name) { return function() { console.log(`User: ${name}`); }; } const user1 = createUser("Rushikesh"); user1(); // User: Rushikesh 🎯 Interview Questions: ❓ What is closure in JavaScript? ❓ Where are closures used in real applications? ❓ How closures help in data privacy? #Day4 #JavaScript #FrontendDevelopment #ReactJS #WebDevelopment #CodingInterview #LearnInPublic #Developers
To view or add a comment, sign in
-
💡 JavaScript IIFE (Immediately Invoked Function Expression) and Interview Classic: The setTimeout + var Trap Ever seen this weird-looking function? 👇 (function() { console.log("Hello World"); })(); 🤔 Looks different, right? 🧠 What is an IIFE? 👉 An IIFE (Immediately Invoked Function Expression) is a function that: ✔️ Is defined ✔️ And executed immediately No need to call it separately! 🔍 How does it work? (function(name) { console.log("Hello " + name); })("Javascript"); 👉 Output: Hello Javascript 🚀 Why do we use IIFE? 🔒 1. Creates a private scope Variables inside it cannot be accessed outside (function() { var secret = "hidden"; })(); ❌ secret is not accessible outside 🌍 2. Avoids global scope pollution Keeps your code clean and prevents conflicts. ⚡ 3. Helps with closures (classic interview use-case) This is one of the most famous questions asked in interviews 👇 for (var i = 0; i < 5; i++) { setTimeout(() => { console.log(i); }, 1000); } 🤔 What will be the output? 👉 Most people expect: 0 1 2 3 4 ❌ But the actual output is: 5 5 5 5 5 🧠 What’s happening here? 🔹 var is function-scoped, not block-scoped 🔹 The loop finishes execution first → i becomes 5 🔹 setTimeout runs later (asynchronously) 🔹 All callbacks share the same reference of i 👉 So every console.log prints 5 ✅ How to fix it? 🔹a) Using let (block scope): for (let i = 0; i < 5; i++) { setTimeout(() => { console.log(i); }, 1000); } ✔️ Output: 0 1 2 3 4 🔹b) Using Closure (if you must use var): for (var i = 0; i < 5; i++) { (function(i) { setTimeout(() => { console.log(i); }, 1000); })(i); } What is this (function(i) { ... })(i)? 👉 This is an Immediately Invoked Function Expression (IIFE) (It runs immediately after being defined) So for each loop iteration: 🔹A new function is created 🔹It gets its own copy of i as a parameter 👉How closure helps here Inside the loop: First iteration → i = 0 → function runs with i = 0 → setTimeout remembers this i Second iteration → i = 1 → new function with i = 1 → new closure created 👉 This happens for all iterations So instead of sharing one i, we now have 5 different i values stored separately Final result After 1 second: 0 1 2 3 4 ✅ Each setTimeout prints its own preserved value 🔥 Simple analogy Think of it like: ❌ Without closure → 5 people sharing one notebook ✅ With closure → each person gets their own notebook 🚀 Key takeaway 👉 Closures allow functions to remember the variables from their scope 👉 IIFE creates a new scope for each iteration 👉 That’s why this fixes the var problem #JavaScript #CodingInterview #FrontendDevelopment #WebDevelopment #LearnInPublic
To view or add a comment, sign in
-
🔥 Top 10 JavaScript Interview Questions You Must Know 🔥 (These decide your JS fundamentals) 1️⃣ var vs let vs const var → function scoped let / const → block scoped 👉 const is preferred by default. 2️⃣ What is Hoisting? Variables and functions are moved to the top during execution. 👉 let and const are hoisted but not initialized. 3️⃣ What is Closure? A function remembers variables from its outer scope. 👉 Very common and very important. 4️⃣ == vs === == → compares value (type conversion) === → compares value + type 👉 Always prefer ===. 5️⃣ What is the Event Loop? It handles async operations like callbacks and promises. 👉 Explains how JS is non-blocking. 6️⃣ Promise vs Callback Promise → cleaner, chainable, better error handling Callback → can cause callback hell 👉 Promises improved async code. 7️⃣ What is this keyword? this depends on how a function is called. 👉 Context matters, not where it’s written. 8️⃣ What is Debouncing and Throttling? Debouncing → delays execution Throttling → limits execution rate 👉 Used for performance optimization. 9️⃣ What is Spread vs Rest operator? Spread → expands values Rest → collects values 👉 Same syntax, different use. 🔟 What is Prototype in JavaScript? Objects inherit properties via prototype chain. 👉 Core concept behind JS inheritance. 💡 JavaScript interviews test concepts, not syntax. 💪 One goal – SELECTION #javascript #Interview #questions #mostasking #important #save
To view or add a comment, sign in
-
Here’s something commonly asked in JavaScript interviews 👇 Shallow vs Deep Copy Shallow Copy Copies only top-level properties. Nested objects are copied by reference, so changes affect the original. 👉 Ways: Object.assign(), spread (...), Array.from() Deep Copy Creates a fully independent copy, including nested objects. A common approach: JSON.parse(JSON.stringify(obj)) ⚠️ Catch with JSON.stringify() It fails for: • functions (removed) • undefined (removed or become null if arr) • Date (becomes string) • NaN / Infinity (become null) • Map, Set, RegExp (structure lost) • circular references (error) ✅ Better approach const newObj = structuredClone(obj) ✔ Handles most cases (Map, Set, Date, circular refs) ❌ Still can’t clone functions 🔥 Advanced: Custom Deep Clone If you also want to handle functions, you need a custom solution: function deepClone(obj) { if (obj === null || typeof obj !== "object") return obj; if (obj instanceof Date) return new Date(obj); if (obj instanceof RegExp) return new RegExp(obj); if (typeof obj === "function") return obj.bind({}); if (Array.isArray(obj)) { return obj.map(item => deepClone(item)); } const cloned = {}; for (let key in obj) { cloned[key] = deepClone(obj[key]); } return cloned; } ⚠️ Note: • Functions are copied by reference (true cloning isn’t really possible) 💡 Takeaway • Use shallow copy for simple cases • Use structuredClone() for most real scenarios • Use custom clone only when you need full control Don't forget to follow Mohit Sharma 🚀 for more. #JavaScript #Frontend #WebDevelopment #InterviewPrep #ReactJS
To view or add a comment, sign in
-
🚀 JavaScript Interview Questions Every Developer Should Know Here are some useful JS questions with simple answers 👇 🔹 1. What is the output? console.log(typeof null); 👉 Answer: "object" 💡 This is a well-known JavaScript bug. 🔹 2. What is closure? 👉 A closure is a function that remembers variables from its outer scope even after the outer function has finished execution. function outer() { let count = 0; return function inner() { count++; return count; }; } 🔹 3. Difference between == and ===? 👉 == → compares value (loose equality) 👉 === → compares value + type (strict equality) 🔹 4. What is hoisting? 👉 JavaScript moves variable and function declarations to the top of their scope before execution. 🔹 5. What will be the output? let a = 10; (function() { console.log(a); let a = 20; })(); 👉 Answer: ❌ ReferenceError 💡 Due to Temporal Dead Zone (TDZ) 🔹 6. What is event loop? 👉 It handles async operations by managing the call stack and callback queue. 🔹 7. What is this keyword? 👉 Refers to the object that is calling the function (depends on context). 🔹 8. What is a promise? 👉 A promise represents a value that may be available now, later, or never. 🔹 9. What is async/await? 👉 Syntactic sugar over promises to write async code like synchronous code. 🔹 10. What is debounce? 👉 Limits how often a function runs. Useful for search inputs. 🔥 Save this for your next interview 💬 Comment your favorite question 🔁 Share with your developer friends #JavaScript #WebDevelopment #Frontend #InterviewPrep #Coding
To view or add a comment, sign in
-
🚫 Think you know JavaScript? Try answering these 👇 💡 50 questions that separate beginners from pros 📉 Most developers fail here in interviews 🚀 Crack any JS interview after mastering these Top 50 JavaScript Interview Questions & Answers ⚡🔥 | Crack Frontend Interviews Easily Preparing for a JavaScript interview? This is your ultimate checklist ✅ These questions are frequently asked in frontend, full-stack, and product-based companies. 💡 Covers: ✔ Core JavaScript Concepts ✔ Closures, Hoisting, Scope ✔ Async Programming ✔ Arrays & Objects ✔ ES6+ Features ✔ Real Interview Scenarios 📚 Top 50 JavaScript Interview Questions 🔹 Basics & Core Concepts What is JavaScript? Difference between var, let, and const What is hoisting? What is scope in JS? What is a closure? Difference between == and === What are data types in JS? What is NaN? What is undefined vs null? What is type coercion? 💬 How many can you answer without Googling? 📌 Save this for your next interview 🔁 Share with your developer network 🔗 Social Links 📸 Instagram: https://lnkd.in/gW2PeGEp 🎥 YouTube: https://lnkd.in/gEB2UqRB #JavaScript #FrontendDeveloper #WebDevelopment #CodingInterview #Programming #Developers #TechJobs #LearnJavaScript #CodingTips #FullStackDeveloper #SoftwareEngineer #TechCareer #InterviewPrep #ES6 #DeveloperLife#CodeWithIndu
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