+ 1
Understanding "this" keyword
What will be output? var x = 3; var foo = { x: 2, baz: { x: 1, bar: function() { return this.x; } } } var go = foo.baz.bar; console.log(go()); console.log(foo.baz.bar());
7 Answers
+ 4
When you declare the go, the "this" scope refers to the global scope. That's why it returns 3. The other one is self explanatory.
+ 3
x=3 is of global scope and hence the first call returns 3.
The second accesses the internal variable x=1 SO 3,1đ¤
+ 2
Is this still the current object?
+ 1
3,1
0
1,1
0
It's already explained, the answer is
3,1
0
Prometheus [EXAMS]đ¸đŹ by "global" do you mean a value that isn't in a function? Cause that's the only way I seem to understand it.