javascript - Why does this loop produce undefined? -
why there 11th iteration, , why 'undefined' printed during it?
var num = 10; var start = 0; function x(){ while (start <= num){ console.log(start + '<br>'); start++; } } console.log(x());
because x() not return when console.log() it.
var num = 10; var start = 0; function x(){ while (start <= num){ console.log(start); start++; } } x();
if return in function output return.
var num = 10; var start = 0; function x(){ while (start <= num){ console.log(start); start++; } return 'end'; } console.log(x());
now function returns 'end'.
Comments
Post a Comment