Browser - (Window | Tab) (Javascript Global scope)



  • The party that is visible for the user is known as the viewport
  • The document property of the window object points to the DOM document loaded in that window (ie in that tab)



Open the console and type window.


  • A window for a given document can be obtained using the document.defaultView property.
  • The window variable


The total size (seen and not seen). This is a window calculation, not the viewport but it can help (ie if you have element positioned absolutely outside, the innerwidth will be greater than the viewport.

The outside Width takes the whole window browser width

console.log("innerWidth: "+window.innerWidth)
console.log("innerHeight: "+window.innerHeight)

Does Javascript run in the browser ?

To test if the script is running in the browser or in node, you would test if you see the window and document variable


if ( typeof (window) !== "undefined" && window.document !== undefined ) {
  console.log("I'm running in the browser");
} else {
   console.log("I'm not running in the browser, therefore I'm running in Node");


Documentation / Reference

Powered by ComboStrap