Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/437.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript:返回未定义的而不是对象_Javascript_Return - Fatal编程技术网

JavaScript:返回未定义的而不是对象

JavaScript:返回未定义的而不是对象,javascript,return,Javascript,Return,谁能给我解释一下: 为什么这是错误的: if (current <= last) { //here! return { done: false, value: current++ }; } else { return { done: true }; } if(current因为“return”,然后新行是一个完整的语句,它将不返回任何内容,因为return之后没有任何内容,它将返回未定

谁能给我解释一下: 为什么这是错误的:

if (current <= last) {
    //here!
    return
    {
        done: false,
        value: current++
    };
} else {
    return
    {
        done: true
    };
}
if(current因为“return”,然后新行是一个完整的语句,它将不返回任何内容,因为
return
之后没有任何内容,它将返回
未定义的


就好像你要写
return;

@Tushar,这不是你所标记的问题的两倍。但是还有一个类似的问题。@CodeiSir你能发布你的链接吗it@Tushar我找不到它,但我编辑了这篇文章的标题,这样以后会更容易找到
if (current <= last) {
    //error here
    return {
        done: false,
        value: current++
    };
} else {
    return {
        done: true
    };
}