JavaScript Function Behavior with Undefined and Extra Args

🚨JavaScript Interview Question What will be the output? function greet(name) { if (name === undefined) { console.log("Hello, guest!"); } else { console.log("Hello, "+ name); } greet(); greet("Anas"); greet("Anas", "How are you?"); Looks simple... but there's a twist What will be the output? Why does the last call behave differently? Bonus: How does JavaScript handle extra arguments? #JavaScript #FrontendInterview #WebDevelopment #CodingInterview #ProductBasedCompany

Hello guest! Hello AmruthaHello Vineethin first no arguments means undefined again function will be invoked in call stack and during code creation phase it got argument Amrutha and again it is only accepting one argument so output will be Vineeth

Like
Reply

To view or add a comment, sign in

Explore content categories