function abc(a) { return (function(y){ return y+1; }) (++a)+a; } alert(abc(2)); | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

function abc(a) { return (function(y){ return y+1; }) (++a)+a; } alert(abc(2));

How come the output 7 is possible for this?i need exaplaination .

12th Apr 2019, 2:43 PM
Leela Vidisha Mandapaka
Leela Vidisha Mandapaka - avatar
2 Answers
+ 3
//You put an argument a as 2. a gets pre-incremented by one and so now equals 3. You add up 3+3 and get 6. But you asked the function to return the result plus one (return y+1) and so you receive 7 in the end. answered by: @kuba https://www.sololearn.com/Discuss/482453/?ref=app
12th Apr 2019, 3:13 PM
Sudarshan Rai
Sudarshan Rai - avatar
12th Apr 2019, 4:02 PM
Leela Vidisha Mandapaka
Leela Vidisha Mandapaka - avatar