![](/img/trans.png)
[英]Why when I do a console.log is my object within a function returned as 'undefined'? (Learning about creation phase, execution phase)
[英]When I console.log type of my function which returns an object it gives undefined. I don't understand why
我不明白为什么这段代码的结果不确定?
function f() {
return
{
x: 0
};
}
console.log(type of f());
typeof
是一个单词。 另外,您正在调用函数,因此您正在评估它的返回值,由于自动分号插入,该值在代码中未定义。
来自https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Statements/return
return语句受分号自动插入(ASI)的影响。 return关键字和表达式之间不允许使用行终止符。
function f() { return //this is treated as though it had a ; { x: 0 }; } console.log(typeof f()); console.log(typeof f);
function f() { return { x: 0 }; } console.log(typeof f()); console.log(typeof f);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.