What will the console output be and why? (function(x) { return (function(y) { console.log(x); })(2) })(1); Last edited: 21-Jun-16 11:17 AM
A_GuY · Jun 21, 2016 11:13 AM · 11,293 views
Its easy bro, output is 1. Its because you have passed 1 as argument in closure, 'x' will have value 1. As in Javacript inner function has access to its parent function variables, so value of x inside inner function will stay 1. Its easy(not tricky) because variable value has not been overidden as you are using 'y' as argument in inner function.
dev P · Jun 21, 2016 1:07 PM
This conversation is preserved exactly as it was on the original Sajha.com and can't accept new replies.
Start a New Discussion