Why does every JS object have one undefined property [duplicate]

南楼画角 提交于 2019-12-02 07:14:28

That's not a property, it's the return of function that developer tools prints.

Example:

console.logger = function(p){
           console.log(p);
           return "logged"
      }
var obj = {a:'a',b:'b'};
for (var p in obj){
   console.logger(p);
}

a          // logs the property
b          // logs the property
"logged"   // logs the return of logger function, undefined in case nothing's returned
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!