If you use strict mode
like in "use strict";
then a
will need to be defined using the keyword var
or as a function parameter function(a){}
. window.a
will always be a property in the global object window
and this
will be the "current execution" scope that is going to be determined by wether you are inside of a constructed object i.e (new FN()
) or when binding a function to a specific object
var obj = {a:'hi'};
function greet(){console.log(this.a)};
obj.greet.bind(obj)(); //prints 'hi'
failing to comply with these rules while on strict mode will cause a compiler error.
now if you are not on strict mode not defined variable a
=== window.a
as the system will look for a local declaration and if none is found it will assume is because is meant to be part of the global object(window when in a browser). And when in a non explicitly declared execution scope this
will refer to the global object too so in some cases on plane scripts when not in strict mode a === window.a === this.a. Is because of these "confusing" behavior that the use of "strict mode" is advised. I hope this helps