JavaScript Interview Trap: Arrow Function vs Normal Function

🚀 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

  • graphical user interface, application

To view or add a comment, sign in

Explore content categories