Global Variables/Properties, globalThis

Video

JavaScript Notes

HTML - in browser
    <!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
      </head>
      <body>
        <script>
          // https://caniuse.com/#feat=mdn-javascript_builtins_globalthis
    
          let lll = 'declared with let';
          var vvv = 'declared with var';
    
          (function test() {
            nnn = 'declared without either';
            // console.log(this);
            // console.log(window);
            // console.log(globalThis); //added in NodeJS 12.4
            console.log(lll, globalThis.lll);
            console.log(vvv, globalThis.vvv);
            console.log(nnn, globalThis.nnn);
          })();
        </script>
      </body>
    </html>
JavaScript - in Node JS
    let lll = 'declared with let';
    var vvv = 'declared with var';
    
    (function test() {
      nnn = 'declared without either';
      // console.log(this);
      // console.log(global);
      // console.log(globalThis);
      console.log(lll, globalThis.lll);
      console.log(vvv, globalThis.vvv);
      console.log(nnn, globalThis.nnn);
    })();