The screen object in JavaScript is part of the Browser Object Model (BOM) and provides information about the user's screen or monitor.
It contains properties that give details about the screen's size, color depth, and pixel density.
Returns the total width of the user's screen in pixels.
console.log("Screen Width:", screen.width);
console.log("Screen Height:", screen.height);
Returns the total height of the user's screen in pixels.
console.log("Available Screen Width:", screen.availWidth);
console.log("Available Screen Height:", screen.availHeight);
Returns the width of the user's screen excluding taskbars or other system elements.
console.log("Color Depth:", screen.colorDepth);
console.log("Screen Orientation:", screen.orientation.type);
Returns the height of the user's screen excluding taskbars or other system elements.
Returns the number of bits used to represent the color of a pixel.
Returns an object describing the current orientation of the screen, either in landscape or portrait mode.
The type property can have values like "landscape-primary", "landscape-secondary", "portrait-primary", or "portrait-secondary".
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Screen Object Example</title> </head> <body> <script> console.log("Screen Width:", screen.width); console.log("Screen Height:", screen.height); console.log("Available Screen Width:", screen.availWidth); console.log("Available Screen Height:", screen.availHeight); console.log("Color Depth:", screen.colorDepth); console.log("Pixel Depth:", screen.pixelDepth); console.log("Screen Orientation:", screen.orientation.type); </script> </body> </html>