0

I know that in 'use strict' this inside the functions gets undefined value, but I mentioned that if I call window.foo() instead of foo(), this gets window value, here is code example:

'use strict';

function logThis() {
    console.log(this);
}

window.logThis() // window
logThis() // undefined

I would like to understand why this happens.

Zaren Wienclaw
  • 181
  • 4
  • 15
kexek
  • 29
  • 9
  • https://stackoverflow.com/questions/29514382/global-functions-in-javascript – mplungjan Dec 13 '18 at 15:05
  • 1
    "I know that in 'use strict' this inside functions gets undefined value," — No. That's only true if you call a function with no context. The behaviour of `this` is all other situations (e.g. then there is a context, for arrow functions, for use of bind/call/apple, or for use of new) is unchanged. – Quentin Dec 13 '18 at 15:05
  • https://stackoverflow.com/questions/47909969/javascript-function-scope-variable-is-available-in-the-global-scope – mplungjan Dec 13 '18 at 15:06
  • [This may provide a little bit more of an insight @alexanderrodin](https://stackoverflow.com/a/14328520/2647442) – Marie Dec 13 '18 at 15:07
  • 1
    Possible duplicate of [Global functions in javascript](https://stackoverflow.com/questions/29514382/global-functions-in-javascript) – mikeb Dec 13 '18 at 15:19

0 Answers0