🚀 JavaScript Interview Trap: Arrow Function vs Normal Function (arguments) Most developers think they know this… but get caught in interviews 👇 ❓Question function normal() { console.log(arguments); } const arrow = () => { console.log(arguments); }; normal(1, 2, 3); arrow(1, 2, 3); Output : normal(1,2,3) → [1, 2, 3] arrow(1,2,3) → ReferenceError ! 🤔Why? 👉 Normal functions have their own arguments object 👉 Arrow functions do NOT have arguments Instead, arrow functions inherit arguments from their outer (lexical) scope ⚠️ Interview Twist function outer() { const arrow = () => { console.log(arguments); }; arrow(); } outer(1, 2, 3); ✔️ Output → [1, 2, 3] 💡 Here, the arrow function borrows arguments from outer() Best Practice : Use rest parameters instead of arguments: const arrow = (...args) => { console.log(args); }; arrow(1, 2, 3);// [1, 2, 3] Final Takeaway : 👉 “Arrow functions don’t have their own arguments; they inherit it from the lexical scope.” Drop your comments below 👇 #JavaScript #WebDevelopment #Frontend #CodingInterview #JS #Developers #Programming
JavaScript Interview Trap: Arrow Function vs Normal Function
More Relevant Posts
-
🚀 𝗖𝗹𝗼𝘀𝘂𝗿𝗲𝘀 𝗶𝗻 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 — 𝗢𝗻𝗲 𝗼𝗳 𝘁𝗵𝗲 𝗠𝗼𝘀𝘁 𝗔𝘀𝗸𝗲𝗱 𝗜𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄 𝗤𝘂𝗲𝘀𝘁𝗶𝗼𝗻𝘀! If you’ve ever prepared for a JavaScript interview, you’ve definitely come across closures. But do you truly understand them? In simple terms: A closure is when a function “remembers” the variables from its outer scope even after that outer function has finished executing. 𝗪𝗵𝘆 𝗶𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄𝗲𝗿𝘀 𝗹𝗼𝘃𝗲 𝘁𝗵𝗶𝘀 𝗾𝘂𝗲𝘀𝘁𝗶𝗼𝗻? Because it tests your understanding of: • Scope • Lexical environment • Memory behavior in JavaScript Quick Example: function outer() { let count = 0; return function inner() { count++; console.log(count); }; } const counter = outer(); counter(); // 1 counter(); // 2 Here, inner() still has access to count even after outer() is executed — that’s a closure! Checkout the full video here: 👉https://lnkd.in/gBkyP54r Follow Alpna P. for more related content! 🤔 Having Doubts in technical journey? 🚀 Book 1:1 session with me : https://lnkd.in/gQfXYuQm 🚀IG: https://lnkd.in/gTQhjM_5 🚀 Get Complete React JS Interview Q&A Here: https://lnkd.in/d5Y2ku23 🚀 Get Complete JavaScript Interview Q&A Here: https://lnkd.in/d8umA-53 #JavaScript #Closures #WebDevelopment #Frontend #CodingInterview #LearnToCode #Developers #CodeWithAlpana Gaurav Patel
To view or add a comment, sign in
-
🚫 Still confused about Lexical Scope vs Other Scopes in JavaScript? This is one of the most asked concepts in frontend interviews — and many developers still get it wrong. Let’s simplify 👇 👉 Lexical Scope (Static Scope) Functions remember where they were defined, not where they are called. That’s why inner functions can access variables from their outer functions. 👉 Types of Scope you MUST know: ✔️ Global Scope – accessible everywhere ✔️ Function (Local) Scope – inside functions only ✔️ Block Scope – inside {} (let & const) 💡 Interview Tip: If you understand how scope works with closures, you’ll crack many tricky JavaScript questions easily. 📌 In the example above: The inner function accesses outerVar because of lexical scope, not because it’s called there. 🔥 Master this → Level up your JavaScript fundamentals. 💬 Comment “SCOPE” if you want more such interview-ready posts 🔁 Share with someone preparing for frontend interviews #javascript #frontenddeveloper #webdevelopment #codinginterview #jsconcepts #100daysofcode #reactjs #developers #programming #interviewprep #techlearning #learnjavascript #scope #closures
To view or add a comment, sign in
-
-
🚀 JavaScript Cheat Sheet every developer should save 👇 If you're learning JavaScript or preparing for interviews… 👉 this is something you’ll keep coming back to again and again. 📚 This cheat sheet covers everything you need: ✨ Variables (var, let, const) 📦 Arrays & methods (push, pop, slice, splice) ⚙️ Functions & loops 🔢 Operators & conditions 🔤 Strings & regex 📊 Numbers, Math & Dates 🌐 DOM manipulation 🧭 Browser APIs 🖱️ Events (mouse, keyboard, forms) ⚠️ Error handling 💡 Not just basics… real-world concepts included: 👉 DOM nodes & element methods 👉 Browser window properties 👉 Event handling (🔥 interview favorite) 🔥 Why this is useful? ➡️ Quick revision before interviews ➡️ Handy while coding ➡️ Saves hours of searching 📌 Pro Tip: Don’t try to memorize everything ❌ Use it while building projects ✅ #javascript #js #frontend #interviews #interview #uideveloper #frontenddeveloper
To view or add a comment, sign in
-
JavaScript interview questions I see being asked again and again Although these are basics, they are often overlooked while preparing for more complex topics. These are some of the most commonly asked JavaScript questions across interviews, especially when the focus is on fundamentals and real-world understanding. 1. What is the event loop in JavaScript? 2. What is the difference between "var", "let", and "const"? 3. What is closure and how is it used? 4. What is hoisting in JavaScript? 5. What is the difference between "==" and "==="? 6. What are promises and how do they work? 7. What is the difference between synchronous and asynchronous code? 8. What is "this" in JavaScript and how does it behave? 9. What is the difference between "map", "filter", and "reduce"? 10. What is prototypal inheritance? 11. What are higher-order functions? 12. What is debouncing and throttling? 13. What is the difference between "null" and "undefined"? 14. What is the difference between "call", "apply", and "bind"? 15. What is a polyfill? Can you write a polyfill for "bind"? 16. What is the difference between shallow copy and deep copy? 17. What is event delegation? 18. How does "setTimeout" work under the hood? 19. What is the difference between "setTimeout" and "setImmediate"? 20. What are microtasks and macrotasks? 21. What is currying in JavaScript? 22. What is memoization? 23. What is the difference between "Object.freeze" and "Object.seal"? 24. How does garbage collection work in JavaScript? Strong fundamentals in JavaScript often make a noticeable difference in how you approach real-world problems. Which of these do you find most interesting or tricky? #javaScript #webdevelopment #programming #softwareengineering #InterviewPrep #interview
To view or add a comment, sign in
-
JavaScript interview questions I see being asked again and again Although these are basics, they are often overlooked while preparing for more complex topics. These are some of the most commonly asked JavaScript questions across interviews, especially when the focus is on fundamentals and real-world understanding. 1. What is the event loop in JavaScript? 2. What is the difference between "var", "let", and "const"? 3. What is closure and how is it used? 4. What is hoisting in JavaScript? 5. What is the difference between "==" and "==="? 6. What are promises and how do they work? 7. What is the difference between synchronous and asynchronous code? 8. What is "this" in JavaScript and how does it behave? 9. What is the difference between "map", "filter", and "reduce"? 10. What is prototypal inheritance? 11. What are higher-order functions? 12. What is debouncing and throttling? 13. What is the difference between "null" and "undefined"? 14. What is the difference between "call", "apply", and "bind"? 15. What is a polyfill? Can you write a polyfill for "bind"? 16. What is the difference between shallow copy and deep copy? 17. What is event delegation? 18. How does "setTimeout" work under the hood? 19. What is the difference between "setTimeout" and "setImmediate"? 20. What are microtasks and macrotasks? 21. What is currying in JavaScript? 22. What is memoization? 23. What is the difference between "Object.freeze" and "Object.seal"? 24. How does garbage collection work in JavaScript? Strong fundamentals in JavaScript often make a noticeable difference in how you approach real-world problems. Which of these do you find most interesting or tricky? #javaScript #webdevelopment #programming #softwareengineering #InterviewPrep #interview
To view or add a comment, sign in
-
🚀 A Classic JavaScript Interview Question That Still Confuses Developers This question shows up in many frontend interviews 👇 ❓ What will be the output? for (var i = 0; i < 3; i++) { setTimeout(() => { console.log(i); }, 1000); } 🤔 What Most People Expect 0 1 2 ✅ Actual Output 3 3 3 🔍 Why Does This Happen? 👉 var is function-scoped, not block-scoped That means: • There is only one shared variable i • All callbacks reference the same i • By the time setTimeout runs, the loop has finished • Final value of i becomes 3 So every callback prints 3 🧠 Key Concept This question tests: ✔ Closures ✔ Execution context ✔ Event loop behavior 💡 How to Fix It ✅ Using let (block scope) for (let i = 0; i < 3; i++) { setTimeout(() => { console.log(i); }, 1000); } ✔ Output: 0 1 2 ✅ Using IIFE (closure fix) for (var i = 0; i < 3; i++) { ((index) => { setTimeout(() => { console.log(index); }, 1000); })(i); } 🎯 Interview Insight This is not about syntax… 👉 It’s about understanding how JavaScript handles scope and closures And that’s exactly what interviewers are testing. 💬 Have you ever been asked this question in an interview? #JavaScript #FrontendDevelopment #CodingInterview #Closures #WebDevelopment #ReactJS #FrontendEngineer #Programming 👉 Follow Rahul R Jain for more real interview insights, React fundamentals, and practical frontend engineering content.
To view or add a comment, sign in
-
Most Asked JavaScript Interview Question: Flatten a Nested Array (Without Using .flat()) There are two common ways to flatten an array in JavaScript: 1️⃣ Using the built-in .flat() method 2️⃣ Using recursion (important for interviews) Using Recursion let arr = [[1, 2, 3, 4, 1, 2], 3, 4, [3, 1], 3, 4, 5]; let flat = []; function flatArrayFunc(arr, flat) { for (let i = 0; i < arr.length; i++) { if (Array.isArray(arr[i])) { flatArrayFunc(arr[i], flat); } else { flat.push(arr[i]); } } } flatArrayFunc(arr, flat); console.log(flat); #JavaScript #CodingInterview #FrontendDeveloper #WebDevelopment
To view or add a comment, sign in
-
🚀 Day 5 – Crack Interviews Series 🔹 Topic: What is this keyword in JavaScript? "this" refers to the object that is executing the current function. 👉 Its value depends on how the function is called, not where it is defined. 💡 Real Example: const user = { name: "Priyanshu", greet() { console.log(this.name); } }; user.greet(); // Priyanshu const fn = user.greet; fn(); // undefined (or window in browser) 🎯 Interview Question: What is the value of "this" in arrow functions? 👉 Answer: Arrow functions don’t have their own "this". They inherit it from the surrounding (lexical) scope. 💡 Arrow Example: const obj = { name: "Dev", arrow: () => { console.log(this.name); } }; obj.arrow(); // undefined 💼 Pro Tip: Use arrow functions carefully in objects—especially in methods. 👇 "this" ever confused you in interviews? 👉 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
-
🚀 Want to Crack Interviews with JavaScript? Read This. Most people “learn” JavaScript… But very few can use it in interviews. The difference? 👉 They don’t just watch tutorials — they master fundamentals. I recently came across a complete JavaScript roadmap that covers everything from: Basics (variables, data types, operators) Core concepts (functions, loops, arrays, objects) Advanced topics (OOPs, DOM, events, promises) Real-world concepts like validation, cookies, and debugging 💡 (As seen in the notes — pages 2 & 3 cover a full roadmap from basics to advanced topics.) Here’s the truth: You don’t need 100 courses. You need: ✔️ Clear concepts ✔️ Consistent practice ✔️ Pattern recognition ⚡ JavaScript interviews don’t test syntax — they test how you think. If you can: Explain closures Work with arrays/objects confidently Understand async behavior Manipulate the DOM 👉 You’re already ahead of 80% of candidates. 📌 Stop jumping between resources. Pick one solid roadmap. Master it. 💬 Are you currently learning JavaScript or planning to start? Drop “JS” below — let’s grow together 🚀 #JavaScript #WebDevelopment #CodingInterview #Frontend #Developers #TechCareers #LearnToCode #CareerGrowth #Programming
To view or add a comment, sign in
-
🚀 Day 3 – Crack Interviews Series 🔹 Topic: What is Async/Await in JavaScript? Async/Await is a cleaner way to handle asynchronous code built on top of Promises. 👉 It makes async code look like synchronous code. 💡 Real Example: function fetchData() { return new Promise((resolve) => { setTimeout(() => resolve("Data received"), 1000); }); } async function getData() { const result = await fetchData(); console.log(result); } getData(); 🎯 Interview Question: What happens if we don’t use "await" inside an async function? 👉 Answer: The function will return a Promise immediately without waiting for the result. 💼 Pro Tip: Always use "try...catch" with async/await for proper error handling. 👇 Do you use async/await in all your projects? #javascript #webdevelopment #nodejs #frontend #interviewprep #coding #developers
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