Window

JS Window Object is the global object in JavaScript. For a web browser, window object tell information about current browser window. Window Object is also the global object of browser environment.

window object is available in browser environment only. In other environment's, there is no window object. For exp, in Node JS, global is used instead of window object.

All global variables and functions are windows properties and methods. See Example


    var x="hello js";
    var y=function(){ return "hi"};
    
    window.x;          // return "hello js"
    window.y();        // return "hi"
    

But Global const and let are not windows properties and methods.


    let x="hello js";
    let y=function(){ return "hi"};
    const pi=Math.PI;
    
    
    window.x;            // return undefined
    window.y;            // return window.y is not a function 
    window.pi            // return undefined 

Window Properties

Window Properties
Property Details Use
innerWidth width of window
innerHeight height of window
devicePixelRatio ratio of physical resolution by actual resolution

Window Methods

JS Window Methods or build in functions.

Window Methods
Method Use
window.open()Open a new browser window. For exp
window.open("print.html","_blank","width=400,height=500,top=100,left=300,resizable=yes")
window.close()Close browser window opened by window.open method. For exp
window.close()
window.print()Print current browser window. Exp
window.print()
window.resizeTo()resize browser to parameter inside. For exp window.resizeTo(600,400) will resize window to 600 by 400.
window.moveTo move window to left top corner of screen