console.log(this) in global scope returns undefined

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


console.log(this) in global scope returns undefined



I have created a script which logs the this variable to the console in the global scope. If I launch the script in the browser it returns undefined. eg.


console.log(this); //returns undefined



However if I enter the same command directly in the browser console it returns the window object. Which is what I was expecting. eg.



console.log(this); //returns Window {postMessage: ƒ, blur: ƒ, focus: ƒ, close: ƒ, frames: Window, …}


console.log(this); //returns Window {postMessage: ƒ, blur: ƒ, focus: ƒ, close: ƒ, frames: Window, …}



Why is the behavior/output of logging 'this' to the console different in the browser console and different while expecting the output from a script?









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Kn5729BXr
D79GQ,03HerIG93VBhSQaR85zgplKZf

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

Visual Studio Code: How to configure includePath for better IntelliSense results