function foo() {
this.baz = "baz";
console.log(this.bar + " " + baz);
}
var bar = "bar";
var baz = new foo(); // "undefined undefined"
foo(); // "bar baz"
When i am running above function the output is undefined undefined
. I don't understand why the values of both bar
and baz
are not showing in console log.
but when i am calling simply foo()
, output in console is "bar baz"
. why is like that?