Day 8/50 – JavaScript Interview Question? Question: What's the difference between == and === in JavaScript? Simple Answer: == (loose equality) performs type coercion before comparison, while === (strict equality) checks both value and type without any conversion. 🧠 Why it matters in real projects: Using === prevents subtle bugs caused by unexpected type coercion. It makes your code more predictable and is considered a best practice in modern JavaScript development. Most linters enforce strict equality by default. 💡 One common mistake: Thinking that == is just "more forgiving" without understanding the complex coercion rules that can lead to confusing results like [] == ![] being true. 📌 Bonus: // Confusing results with == 0 == false // true '' == false // true null == undefined // true '0' == 0 // true // Clear and predictable with === 0 === false // false '' === false // false null === undefined // false '0' === 0 // false // Exception: checking for null/undefined if (value == null) // checks both null AND undefined #JavaScript #WebDevelopment #Frontend #LearnInPublic #InterviewQuestions #Programming #TechInterviews
JavaScript equality operators: == vs === explained
More Relevant Posts
-
Day 13/50 – JavaScript Interview Question? Question: What is hoisting in JavaScript? Simple Answer: Hoisting is JavaScript's behavior of moving declarations to the top of their scope during the compilation phase. Function declarations are fully hoisted, var declarations are hoisted but initialized as undefined, and let/const are hoisted but remain in the Temporal Dead Zone. 🧠 Why it matters in real projects: Understanding hoisting helps you avoid confusing bugs and write more predictable code. It explains why you can call functions before they're declared and why accessing var variables before declaration returns undefined instead of an error. 💡 One common mistake: Thinking hoisting physically moves code. It doesn't—it's about when variables and functions are registered in memory during the creation phase. 📌 Bonus: // Function hoisting - works! greet(); // "Hello" function greet() { console.log("Hello"); } // var hoisting - returns undefined console.log(name); // undefined (not ReferenceError) var name = "Alice"; // let/const - Temporal Dead Zone console.log(age); // ReferenceError let age = 25; // Function expressions are NOT fully hoisted sayHi(); // TypeError: sayHi is not a function var sayHi = function() { console.log("Hi"); }; #JavaScript #WebDevelopment #Frontend #LearnInPublic #InterviewQuestions #Programming #TechInterviews
To view or add a comment, sign in
-
Day 13/365 – Top #JavaScript Interview Questions 🔥Part2 Q19). What are higher-order functions? Q20). What is currying in JavaScript? Q21). What is an IIFE and why is it used? Q22). What is prototypal inheritance? Q23). What is debouncing and throttling? Q24). What is the difference between the spread operator and rest operator? Q25). What is the difference between Object.freeze() and Object.seal()? Q26). What is the difference between a Promise and an Observable? Q27). What is the difference between slice() and splice()? Q28). How do you optimize performance in JavaScript applications? Q29). What is the difference between synchronous and asynchronous code? Q30). What is the difference between null ,undefined and NaN? Q31). What are object methods like Object.keys(), Object.values(), and Object.entries()? Q32). What is the difference between DOM and BOM? Q33). What is destructuring in JavaScript and how is it useful? Q34). What is the difference between filter() and find()? Q35) How do you handle errors in JavaScript? Q36). What is Object.assign() and how does it work? #javascript #interview #webdevlopment #js #365daysofjs #jsinterview #interviewprepration
To view or add a comment, sign in
-
Day5 of February - JavaScript Interview Coding Questions: 💫 Prepare these coding questions. 💫 Practice it using online JavaScript editors. 1) How do you remove duplicate elements from an array? 2) How do you find the second largest number in an array? 3) How do you reverse a string in JavaScript? 4) How do you check if a string is a palindrome? 5) How do you count occurrences of each element in an array? 6) How do you find the maximum and minimum number in an array? 7) How do you flatten a nested array? 8) How do you sort an array of numbers in ascending and descending order? 9) How do you find missing numbers in a given array sequence? 10) How do you group objects in an array by a specific property? ✨ Appreciate you reading See you in the next post! | Rohini Jugalkumar #JavaScript #InterviewPreparation #Frontend #CodingInterview #FebruaryChallenge
To view or add a comment, sign in
-
Day 10/50 – JavaScript Interview Question? Question: What's the difference between null and undefined? Simple Answer: undefined means a variable has been declared but not assigned a value, or a function doesn't return anything. null is an explicit assignment representing "no value" or "empty." 🧠 Why it matters in real projects: Understanding this distinction helps with API responses, function returns, and optional parameters. null is typically used to explicitly indicate "no object" while undefined usually indicates something wasn't initialized or doesn't exist. 💡 One common mistake: Using typeof null and expecting "null", but it actually returns "object" due to a historical JavaScript bug that was never fixed for backward compatibility. 📌 Bonus: let x; console.log(x); // undefined console.log(typeof x); // "undefined" let y = null; console.log(y); // null console.log(typeof y); // "object" (legacy bug!) // Checking for both if (value == null) { // true for both null AND undefined } if (value === null) { // true only for null } if (value === undefined) { // true only for undefined } #JavaScript #WebDevelopment #Frontend #LearnInPublic #InterviewQuestions #Programming #TechInterviews
To view or add a comment, sign in
-
JavaScript Interview Questions As a Frontend Developer, yeh 5 JS questions almost har interview mein poochay jate hain 👇 1️⃣ What is closure in JavaScript? Closure tab banta hai jab ek function apne outer function ke variables ko access kare even after outer function execution. 2️⃣ Difference between var, let, and const? var → function scoped let → block scoped const → block scoped & cannot be reassigned 3️⃣ What is hoisting? JavaScript variables & functions ko execution se pehle memory mein move kar deta hai (sirf declaration, not initialization). 4️⃣ What is event delegation? Parent element par event listener laga kar child elements ke events handle karna. Performance ke liye useful. 💡 Consistency + Strong fundamentals #JavaScript #FrontendDeveloper #WebDevelopment #InterviewPrep
To view or add a comment, sign in
-
Day 11/50 – JavaScript Interview Question? Question: What is the difference between Promise.all() and Promise.race()? Simple Answer: Promise.all() waits for all promises to resolve (or one to reject) and returns an array of results. Promise.race() returns as soon as the first promise settles (resolves or rejects), ignoring the others. 🧠 Why it matters in real projects: Use Promise.all() when you need multiple API calls to complete before proceeding (like fetching user data and their posts). Use Promise.race() for implementing timeouts or choosing the fastest response from multiple sources. 💡 One common mistake: Not realizing that Promise.all() fails fast—if any promise rejects, the entire operation fails immediately, even if other promises are still pending. 📌 Bonus: // Promise.all - all must succeed const results = await Promise.all([ fetch('/api/user'), fetch('/api/posts'), fetch('/api/comments') ]); // If any fails, all fail // Promise.race - first one wins const result = await Promise.race([ fetch('/api/data'), new Promise((_, reject) => setTimeout(() => reject('Timeout'), 5000) ) ]); // Implements a 5-second timeout // Use Promise.allSettled() to get all results regardless of failures #JavaScript #WebDevelopment #Frontend #LearnInPublic #InterviewQuestions #Programming #TechInterviews
To view or add a comment, sign in
-
💼 JavaScript Interview Question I Cracked Today ❓ “Explain the Event Loop in JavaScript.” My answer (simple & interview-ready): 🧠 JavaScript is single-threaded, but it handles async tasks using the Event Loop. How it works: 1️⃣ Call Stack executes synchronous code 2️⃣ Async tasks go to Web APIs 3️⃣ Promises move to the Microtask Queue 4️⃣ setTimeout goes to the Callback Queue 5️⃣ Event Loop pushes microtasks first, then callbacks 💡 Interview Tip: Even setTimeout(fn, 0) runs after Promises. This question tests: ✔ Async understanding ✔ Execution order ✔ Real-world debugging skills If you’re preparing for frontend interviews, master this one concept — it shows up everywhere. Learning → Practicing → Explaining = Growth 🚀 #JavaScript #EventLoop #InterviewPrep #FrontendDeveloper #WebDevelopment #DevTips
To view or add a comment, sign in
-
One of the most common JavaScript interview questions that catches many beginners off guard! 👇 The Question: What will be the output? for (var i = 0; i < 3; i++) { setTimeout(() => console.log(i), 100); } The Expected Output: 0, 1, 2 The Actual Output: 3, 3, 3 Why does this happen? 🤔 1️⃣ Scope Issue: The keyword var is function-scoped. This means all the setTimeout callbacks are pointing to the same variable i. 2️⃣ The Delay: By the time the first setTimeout executes (after 100ms), the loop has already finished, and the value of i has become 3. The Fix: Use let 💡 Simply changing var to let solves the problem: ✔️ for (let i = 0; i < 3; i++) { setTimeout(() => console.log(i), 100); } Output: 0, 1, 2 Why? Unlike var, let is block-scoped. In every iteration of the loop, a new binding is created for i. Each setTimeout "remembers" its own version of i. Key Takeaway: Avoid var in modern JavaScript. Stick to let and const to prevent scope-related bugs! 🛡️ Did you get it right? Let me know in the comments! 👇 #JavaScript #WebDevelopment #CodingTips #InterviewPrep #Frontend #ReactJS #LearnToCode
To view or add a comment, sign in
-
Day 26/50 – JavaScript Interview Question? Question: What is currying in JavaScript? Simple Answer: Currying transforms a function that takes multiple arguments into a sequence of functions, each taking a single argument. Instead of add(a, b), you get add(a)(b). 🧠 Why it matters in real projects: Currying enables partial application, function composition, and more reusable code. It's fundamental to functional programming libraries like Ramda and is used in Redux middleware, event handlers, and configuration functions. 💡 One common mistake: Over-currying simple functions where it adds complexity without benefit. Use currying when you need partial application or composition, not everywhere. 📌 Bonus: // Regular function function add(a, b, c) { return a + b + c; } add(1, 2, 3); // 6 // Curried version function curriedAdd(a) { return function(b) { return function(c) { return a + b + c; }; }; } curriedAdd(1)(2)(3); // 6 // Practical use: Partial application const add5 = curriedAdd(5); const add5and10 = add5(10); console.log(add5and10(3)); // 18 // Generic curry function function curry(fn) { return function curried(...args) { if (args.length >= fn.length) { return fn.apply(this, args); } return function(...nextArgs) { return curried.apply(this, [...args, ...nextArgs]); }; }; } // Usage const multiply = (a, b, c) => a * b * c; const curriedMultiply = curry(multiply); curriedMultiply(2)(3)(4); // 24 curriedMultiply(2, 3)(4); // 24 - flexible! #JavaScript #WebDevelopment #Frontend #LearnInPublic #InterviewQuestions #Programming #TechInterviews #FunctionalProgramming #Currying #WebDev #InterviewPrep
To view or add a comment, sign in
-
🧩 JavaScript Output-Based Question (call / bind) ❓ What will be logged? 👉 Comment your answer below (Don’t run the code ❌) Correct Output : A 🧠 Why this output comes? (Step-by-Step) 1️⃣ bind() creates a NEW function const bound = greet.bind(a); bind() permanently sets this to object a and returns a new bound function. 2️⃣ call() cannot change a bound this bound.call(b); Once a function is bound: • call() • apply() • bind() again ❌ cannot override the original binding So even though call(b) is used, this still points to a. That’s why : A is printed. 🔑 Key Takeaways ✔️ bind() sets this permanently ✔️ call() and apply() set this only temporarily ✔️ call() cannot override bind() ✔️ This is a very common interview trap If you remember one thing: bind beats call and apply #JavaScript #CallBindApply #InterviewQuestions #FrontendDeveloper #MERNStack #ReactJS
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