What is a Global Object in JavaScript?

JavascriptWeb DevelopmentFront End Scripts

Objects in JavaScript are different from the Global Object. Using the new operator, you cannot create global objects. It comes into existence when the scripting engine is initialized. After it is initialized, the functions and constants are available for use.

A global object allows you to do the following −

  • It gives access to built-in functions and values. Call alert directly like the below code snippet, with window

alert("Demo Text");
// or
window.alert("Demo Text");
  • It also gives access to global function declarations and var variables −

         var str = "Demo Text";
         // using window
         alert( window.str );
Published on 23-Feb-2018 07:22:56