![](/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.