1
let obj = {a:'a',b:'b'};
for (let p in obj){
   console.log(p);
}

Output:

a 
b
undefined

What's up with the undefined property?

vinayakj
  • 5,591
  • 3
  • 28
  • 48
Juraj Petrik
  • 895
  • 1
  • 10
  • 25
  • 5
    Thats not property its `return of function` that `developer tools` prints – vinayakj Jul 26 '15 at 12:56
  • Well do I feel dumb right now. If you repost this as an answer I can accept it – Juraj Petrik Jul 26 '15 at 12:58
  • no problem.. no question is dumb untill you know the answer, also a fun fact developer tools prints the returned response in case of AJAX, even if you have consoled it outside of callback function. – vinayakj Jul 26 '15 at 13:00

1 Answers1

3

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
vinayakj
  • 5,591
  • 3
  • 28
  • 48