答案 0 :(得分:2)
您得到undefined
,因为return
之后有一个新行,因此它从undefined
函数返回doesNotWork
。将其放在同一行中即可使用:
let someArray = {
Person: {
age: 27,
online: true
}
};
function works(obj) {
return ('Person' in obj);
}
console.log("works returns:" + works(someArray));
function doesNotWork(obj) {
//should be in a same line
return ('Person' in obj);
}
console.log("doesNotWork returns:" + doesNotWork(someArray));