Javascript, while loop return

后端 未结 3 906
时光说笑
时光说笑 2020-12-20 17:54
var i = 0;
while(i < 100){
   return \"The number is \" + i;
   i++;
}

What is wrong with my return statement? Why can I return a string plus a

3条回答
  •  情书的邮戳
    2020-12-20 18:07

    return means end of function and return some value. Any statements after return statement will not be executed and the execution of a function will terminate at return statement. So, return in your case will make the loop to execute only one and terminate it.

提交回复
热议问题