This explicit binding example gets me undefined when I run it on code editor --> var scope ='global'; function test(){console.log(this.scope); test() Edit: But when I run this in chrome console then I get "global" then undefined. Why is this?
When you run a function in Chrome console, it prints the return value of that function by default. So one of the undefined would be the return value of your test function.
This explicit binding example gets me undefined when I run it on code editor --> var scope ='global'; function test(){console.log(this.scope); test()
Edit: But when I run this in chrome console then I get "global" then undefined. Why is this?
When you run a function in Chrome console, it prints the return value of that function by default. So one of the undefined would be the return value of your test function.