
10 JavaScript Output Questions That Look Innocent but Might Betray You in Interviews
JavaScript was written in 10 days, and we've been debugging it for decades. Microsoft, Amazon, Atlassian, Walmart, eBay, and several similar big tech companies test candidates' JavaScript knowledge with such quirky problems. So if you are a frontend developer - React, Next.js, or maybe Node.js developer, you know JavaScript doesn't test syntax in interviews. It tests mental models. If you don't understand how the engine thinks-hoisting, closures, the event loop, mutation-these questions will humble you very quickly. Let's break 10 of them as a JS engine would. Are you ready? Cool, give me the output for … Problem 1: Modifying Array While Iterating (forEach + splice) var aa = [ 1 , 2 , 3 , 4 , 5 , 6 ]; aa . forEach ( i => { console . log ( i ); if ( i > 3 ) aa . splice ( aa . indexOf ( i ), 1 ); }); Mutation during iteration + how forEach handles index internally. Output : 1 2 3 4 6 Explanation: forEach moves forward using the internal index. When you remove 4, the array becomes [1,2,3,
Continue reading on Dev.to React
Opens in a new tab




