Flat Preloader Icon

Screen Object

The Screen object in JavaScript provides information about the user’s screen or display device. It represents the physical display properties such as width, height, color depth, pixel density, and orientation.

Properties:

  • screen.width:

    • Returns the width of the screen in pixels.
  • screen.height:

    • Returns the height of the screen in pixels.
  • screen.availWidth:

    • Returns the available width of the screen (excluding taskbars, etc.) in pixels.
  • screen.availHeight:

    • Returns the available height of the screen (excluding taskbars, etc.) in pixels.
  • screen.colorDepth:

    • Returns the color depth of the screen (number of bits per pixel).
  • screen.pixelDepth:

    • Returns the pixel depth of the screen (number of bits per pixel).
  • screen.orientation:

    • Returns an Orientation object representing the orientation of the screen (e.g., portrait-primary, landscape-primary, etc.).

Methods:

  • screen.lockOrientation():
        • Locks the orientation of the screen to the specified orientation (if supported by the device).
  • screen.unlockOrientation():

    • Unlocks the orientation of the screen, allowing it to rotate freely (if previously locked).
				
					console.log("Screen width:",
screen.width);
console.log("Screen height:",
screen.height);
console.log("Available width:",
screen.availWidth);
console.log("Available height:", 
screen.availHeight);
console.log("Color depth:",
screen.colorDepth);
console.log("Pixel depth:",
screen.pixelDepth);
console.log("Screen orientation:", 
screen.orientation.type);

// Lock the screen orientation to landscape
screen.lockOrientation("landscape");