I have executed the following code both in VS Code and browser console
var message = 'I am your teacher'
function executeWorkshop(greeting){
return function ask(){
console.log(`${greeting}, ${this.message}`);
}
}
executeWorkshop("Hi")();
Outputs
VS Code:
Hi, undefined
Browser:
Hi, I am your teacher
For web browsers, we have a window object. It provides the browser window functionality and also plays the role of a global object. When scripts create global variables in the web browsers, they're created as members of the global object(window object).
In Node.js, This is not the case. NodeJs has something called global object.
Here are some facts: