With regard to global variables, why is the output under node and browser different? Is it because of strict mode? Ask for a detailed explanation

node version 10.13.0

var name = "window";
function foo() {
    var name = "inner";
    console.log(this.name);
}
foo();  // undefined

chrome 69 strict mode and non-strict mode

is the difference in strict mode? Is the strict mode of
node enabled automatically?
Thank you guys

Jul.12,2022

the difference is in the scope , node does not enable strict mode by default. In
browser , variables declared under global scope automatically become global variables (an attribute under window). In
node , each module (file) has its own module scope , in which you declare a variable that will not become a global variable of node, but a variable under the scope of this module.


    The this of
  1. in node is actually a {}, which you can print directly in node, so the this.name in node is naturally undefined.
  2. for browsers, in strict mode, if the function is called without specifying an environment object, the this value will not be converted to window, unless the function is explicitly added to an object or apply () or call () is called, otherwise the this value will be undefined.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1be22be-315e5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1be22be-315e5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?