🚨 JavaScript Interview Question What will be the output? console.log([] + []); console.log([] + {}); console.log({} + []); At first glance it looks simple. But the results are surprising because of JavaScript type coercion and how objects convert to strings. Understanding how JavaScript converts types internally is something that appears very often in frontend interviews. Many tricky bugs also come from this behavior. What output do you think this will produce? #JavaScript #FrontendInterview #ReactJS #FrontendDeveloper #FrontendArchitecture #ProductBasedCompany
console.log([] + []); // "" console.log([] + {}); // "[object Object]" console.log({} + []); // 0
Console.log([] +[] ) or without console gives empty string Console.log( {} + [] ) gives [ object object ] And if without Console gives 0 And Console.log ( [] + {} ) gives [ object object ] and if without Console gives ' [ object object ]'
Type Coercion🙏
Small hint: When objects participate in + operations, JavaScript tries to convert them to primitives using toString() or valueOf().