How can it be 6? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can it be 6?

function subst(x,y){ return x; return y; return x-y; } document.write(subst(6, 2));

15th Dec 2022, 11:09 AM
Sony
Sony - avatar
3 Answers
+ 1
A function stops running after a return statement. So this function executes return x (6), and then stops running.
15th Dec 2022, 11:41 AM
HelloWorld
+ 1
Thank you so much for your support.. :)
15th Dec 2022, 11:49 AM
Sony
Sony - avatar
+ 1
No problem ;)
15th Dec 2022, 11:49 AM
HelloWorld