0

I have this snippet of code

function foo() {
    console.log(this.bar);
}

var bar = "bar1";
var o2 = { bar: "bar2", foo: foo };
var o3 = { bar: "bar3", foo: foo };

foo();          // "bar1"
o2.foo();       // "bar2"
o3.foo();       // "bar3"

when run in browser it shows the output

bar1
bar2
bar3

but when run it with node it outputs

undefined
bar2
bar3

Can someone explain why am I getting different outputs?

Frosty
  • 15
  • 6

0 Answers0