🚨 You’re probably using the wrong method… find() vs filter() in JavaScript 👇 const arr = [1, 2, 3, 4, 5]; const one = arr.find(x => x > 2); const many = arr.filter(x => x > 2); 💡 Here’s the difference: 👉 find() → returns FIRST match 👉 filter() → returns ALL matches ⚠️ Common mistake: Using filter() when you only need one value 👉 That means extra unnecessary iterations 🔥 Simple rule: Need ONE → find() Need MANY → filter() ⚠️ Interview trap: find() → undefined filter() → [] 👉 Small concept → Big impact in real projects Which one were you using till now? 👇 Save this for interviews 🚀 Follow for more JavaScript content 🔥 #JavaScript #WebDevelopment #Frontend #Developers #InterviewPrep
find vs filter in JavaScript
More Relevant Posts
-
15 JavaScript interview questions. Promises & Async/Await. Answer karo comments mein 👇 Promises Q1. What is a Promise in JavaScript and why does it exist? Q2. What is the difference between resolve and reject? Q3. What does .then() return? Q4. What is the difference between .catch() and the second argument of .then()? Q5. What does .finally() do? Async/Await Q6. What is async/await and how does it relate to Promises? Q7. What does an async function always return? Q8. Can you use await outside an async function? Q9. What happens if you don't use try/catch with async/await? Q10. What is the difference between sequential and parallel async calls? Promise Methods Q11. What is the difference between Promise.all and Promise.allSettled? Q12. What is Promise.race and when would you use it? React Connection Q13. Why can't useEffect callback be directly async? Q14. What is the standard loading/error/data pattern in React? Q15. What is the difference between async errors and sync errors in React? Full answers + code on GitHub 👇 https://lnkd.in/dj72-XEi #JavaScript #JStoReact #InterviewPrep #WebDevelopment #Frontend #ReactJS #30DayChallenge #JavaScriptTips #FrontendDeveloper #100DaysOfCode
To view or add a comment, sign in
-
🚀 JavaScript Interview Questions (4–5 Years Experience) – Part 2 Taking it a step further with more practical and scenario-based questions: 🔹 What is the difference between call(), apply(), and bind()? 🔹 How does garbage collection work in JavaScript? 🔹 What is a memory leak? How can you avoid it? 🔹 Explain the concept of currying with an example. 🔹 What is the difference between Object.freeze() and Object.seal()? 🔹 How does setTimeout behave inside a loop? 🔹 What is the Temporal Dead Zone? 🔹 Difference between null and undefined? 🔹 What is optional chaining (?.) and nullish coalescing (??)? 🔹 How do you clone an object in JavaScript? 🔹 What is the difference between deep copy and shallow copy? 🔹 How does Promise.all() differ from Promise.allSettled()? 🔹 What are generators and where are they used? 🔹 Explain the concept of module pattern in JavaScript. 🔹 What is tree shaking? 🔹 What are Web APIs and how do they interact with JS? 🔹 What is the difference between for...in and for...of? 🔹 What is the difference between Map and Object? 🔹 What are WeakMap and WeakSet? 🔹 How does error handling work in async/await? 💡 Challenge: Write a custom implementation of debounce or throttle function. #JavaScript #Frontend #InterviewPrep #WebDevelopment #Coding #Developers
To view or add a comment, sign in
-
-
One of the most common JavaScript interview questions: "Why does setTimeout with 0ms delay not run immediately?" Most developers cannot answer this correctly. Here is the full explanation: JavaScript is single-threaded. It can only do one thing at a time. The Event Loop is how it manages everything else. The execution order is always the same: 1 — Synchronous code runs first All regular code on the Call Stack executes immediately. 2 — Microtasks run second Promises, async/await — these run before anything else once the Call Stack is empty. 3 — Macrotasks run last setTimeout, setInterval, DOM events — these wait until ALL microtasks are done. This is why setTimeout with 0ms still runs after a Promise. The Promise is a microtask. setTimeout is a macrotask. Microtasks always win. Understanding this prevents real bugs in production — async state updates, race conditions, unexpected render order. Save this post for your next async debugging session. Have you ever been confused by JavaScript async order? Drop a comment below. #JavaScript #WebDevelopment #Frontend #SoftwareEngineering #AsyncJavaScript
To view or add a comment, sign in
-
-
🚀 JavaScript Interview Questions (4–5 Years Experience) Here are some practical JavaScript questions every mid-level developer should be comfortable with: 🔹 What is the difference between var, let, and const? 🔹 Explain closures with a real-world example. 🔹 What is event delegation and why is it useful? 🔹 Difference between synchronous and asynchronous JavaScript? 🔹 How does the event loop work? 🔹 What are Promises and how do they work internally? 🔹 Difference between async/await and Promises? 🔹 What is debouncing and throttling? 🔹 Explain hoisting in JavaScript. 🔹 What is the difference between == and ===? 🔹 What is a higher-order function? 🔹 Explain this keyword in different contexts. 🔹 What is prototypal inheritance? 🔹 What is memoization and when to use it? 🔹 Difference between shallow copy and deep copy? 🔹 What are arrow functions and how are they different? 🔹 What is currying in JavaScript? 🔹 What is the difference between map(), filter(), and reduce()? 🔹 How does JavaScript handle memory management? 🔹 What are common performance optimization techniques? 💡 Bonus: Can you implement your own Promise, debounce, or bind function? #JavaScript #FrontendDeveloper #WebDevelopment #CodingInterview #ReactJS #Developers
To view or add a comment, sign in
-
-
🔥 JavaScript Interview Question That Trips Many Developers Here’s a simple-looking question that reveals how well you understand this in JavaScript 👇 const obj = { name: 'Alice', greet() { console.log(this.name); }, greetArrow: () => { console.log(this.name); }, }; obj.greet(); obj.greetArrow(); const fn = obj.greet; fn(); ❓ What will be the output? ✅ Answer: Alice undefined undefined 💡 Explanation (Must-Know for Interviews): 1️⃣ obj.greet() Regular function this → refers to obj 👉 Output: Alice 2️⃣ obj.greetArrow() Arrow function Doesn’t have its own this Takes this from outer (global) scope 👉 Output: undefined 3️⃣ fn() Function is detached from object this is lost (defaults to global/undefined) 👉 Output: undefined 🧠 Key Takeaways: ✔ this depends on how a function is called ✔ Arrow functions don’t bind this ✔ Extracting methods can break this 💥 Pro Tip: If you want to preserve this: const fn = obj.greet.bind(obj); fn(); // Alice #JavaScript #Frontend #WebDevelopment #InterviewPrep #CodingInterview #JSConcepts
To view or add a comment, sign in
-
𝐈𝐟 𝐘𝐨𝐮 𝐊𝐧𝐨𝐰 𝐓𝐡𝐞𝐬𝐞 𝐑𝐮𝐥𝐞𝐬, 𝐘𝐨𝐮’𝐥𝐥 𝐍𝐞𝐯𝐞𝐫 𝐁𝐫𝐞𝐚𝐤 𝐂𝐨𝐝𝐞 𝐰𝐢𝐭𝐡 “𝐭𝐡𝐢𝐬” 𝐢𝐧 𝐣𝐚𝐯𝐚𝐬𝐜𝐫𝐢𝐩𝐭! 1. Global Context Outside any function, this refers to the global object window in browsers, global in js. 2. Regular Function (non-strict mode) this refers to the global object (window), even though you're inside a function. 3. Regular Function (strict mode) this is undefined. JavaScript stops the accidental global binding. 4. Object Method When a function is called as a property of an object, this refers to that object. 5. Arrow Function Doesn't have its own this. It inherits this from the surrounding lexical scope wherever the arrow function was written, not called. 6. Constructor Function / new keyword this refers to the newly created object being built. 7. Class Method Same as object method this refers to the instance of the class. 8. call(), apply(), bind() You manually set what this should be. These are the escape hatches. 9. Event Listeners (DOM) this refers to the HTML element that triggered the event but only with regular functions, not arrow functions. 10. Callback Functions this is often lost here. Passing a method as a callback detaches it from its original object. For more insightful content checkout below: 🟦 𝑳𝒊𝒏𝒌𝒆𝒅𝑰𝒏 - https://lnkd.in/dwi3tV83 ⬛ 𝑮𝒊𝒕𝑯𝒖𝒃 - https://lnkd.in/dkW958Tj 🟥 𝒀𝒐𝒖𝑻𝒖𝒃𝒆 - https://lnkd.in/dDig2j75 or Priya Frontend Vlogz 🔷 𝐓𝐰𝐢𝐭𝐭𝐞𝐫 - https://lnkd.in/dyfEuJNt #frontend #javascript #react #interview #interviewpreparation #SDE w3schools.com JavaScript Mastery JavaScript Developer freeCodeCamp
To view or add a comment, sign in
-
-
15 JavaScript interview questions. DOM Manipulation & Events. Answer karo comments mein 👇 DOM Basics Q1. What is the DOM? Q2. What is the difference between querySelector and getElementById? Q3. What is the difference between textContent and innerHTML? Events Q4. What is an event listener and how do you add one? Q5. How do you remove an event listener? Q6. What is event bubbling? Q7. What is the difference between event bubbling and event capturing? Q8. What is e.stopPropagation() and when do you use it? Q9. What is e.preventDefault() and when do you use it? Q10. What is the difference between e.target and e.currentTarget? Event Delegation Q11. What is event delegation and why is it important? Q12. How does React use event delegation internally? Advanced Q13. What are synthetic events in React? Q14. Why should you avoid direct DOM manipulation in React? Q15. What is the difference between mouseenter and mouseover? Full answers + code on GitHub 👇 https://lnkd.in/dj72-XEi #JavaScript #JStoReact #InterviewPrep #WebDevelopment #Frontend #ReactJS #30DayChallenge #JavaScriptTips #FrontendDeveloper #100DaysOfCode
To view or add a comment, sign in
-
🚀 Day 8 – Crack Interviews Series 🔹 Topic: What is Prototype in JavaScript? Every JavaScript object has a hidden property called prototype that allows it to inherit properties and methods from other objects. 👉 This is how inheritance works in JavaScript. 💡 Real Example: function Person(name) { this.name = name; } Person.prototype.greet = function () { console.log("Hello " + this.name); }; const user = new Person("Priyanshu"); user.greet(); // Hello Priyanshu 👉 "greet()" is not inside the object, but still accessible via prototype. 🎯 Interview Question: What is the prototype chain? 👉 Answer: It’s a chain of objects where JavaScript looks for properties if not found in the current object. 💼 Pro Tip: Modern JavaScript uses "class", but under the hood it still works with prototypes. 👇 Have you explored prototype vs class deeply? 👉 Follow the Hireful Jobs channel on WhatsApp: https://lnkd.in/ghaHMBUB Telegram: https://t.me/hireful #javascript #webdevelopment #frontend #nodejs #interviewprep #coding #developers
To view or add a comment, sign in
-
5 JavaScript tricks that made me go "wait... WHAT?" I've been coding for 4 years. These still surprised me. ① Optional Chaining (?.) No more "cannot read property of undefined" crashes. user?.profile?.avatar ✔️ ② Nullish Coalescing (??) Only falls back when value is null or undefined. const name = user.name ?? "Guest" ✔️ ③ Array Destructuring with Skip Skip elements you don't need. const [first, , third] = [1, 2, 3] ✔️ ④ Object Shorthand Stop repeating yourself. { name: name } → { name } ✔️ ⑤ Promise.all() Run multiple async calls at the same time. 10x faster than awaiting one by one. ✔️ JavaScript is weird. But once it clicks — it's magic. ✨ Which one did YOU not know? Drop the number 👇 #JavaScript #WebDevelopment #MERNStack #ReactJS #CodingTips
To view or add a comment, sign in
-
-
Most developers use JavaScript. Only a few actually understand it deeply. That’s the difference between getting rejected and getting selected in frontend interviews. If you want to stand out, these JavaScript concepts are non-negotiable 👇 🧠 Execution Context, Call Stack & Hoisting 🔒 Closures, Scope & Lexical Environment ⚡ Async JavaScript (Promises, Async/Await, Fetch) 🔁 Event Loop, Microtasks & Callback Queue 🧩 Objects, Prototypes & this keyword 🛠️ Call, Apply, Bind 📦 Arrays (map, filter, reduce) 🚀 ES6+ (Destructuring, Spread, Modules) 🌐 DOM Manipulation & Event Delegation 🔥 Debouncing & Throttling 🧪 Error Handling & Memory Management You need strong JavaScript fundamentals. Master this → You’re already ahead of most developers. #javascript #frontenddeveloper #webdevelopment #reactjs #coding #developers #100DaysOfCode
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