Why the value of 'i' is 2, when there is (i<=1)? JS | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why the value of 'i' is 2, when there is (i<=1)? JS

https://code.sololearn.com/WsGLdnP5MVBZ/?ref=app

17th Dec 2022, 10:34 AM
Musojon Abdulvahobov
Musojon Abdulvahobov - avatar
2 Answers
+ 6
function sum(i){ return ++i; } for(var i=0;i<=1;i++){}; //when i<=1 , 2<=1 looo stops so i=2; document.write(sum(i)) // calling sum() with passing i=2 and get return 3 , but it does not modify passed i value so i value remains 2 document.write(i) // prints 2
17th Dec 2022, 10:48 AM
Jayakrishna 🇮🇳
+ 2
Understand. Thanks
17th Dec 2022, 11:02 AM
Musojon Abdulvahobov
Musojon Abdulvahobov - avatar