I am currently working on javascript Function and Objects but there is a little bit confusion.
I have created an object and called its method in the window like
obj.something();
, it gives me result but when I write same code in console like console.log(obj.something());
, it gives me undefined
in the console
So, my question is obviously why & how?
var obj ={
value: 1,
increment: function () {
this.value += 1
// return this
},
add: function (v) {
this.value += v
// return this
},
shout: function () {
console.log(this.value);
// return this
}
};
obj.shout();
console.log(obj.shout());