Js Screen in JavaScript
?? JavaScript Screen Object
The Screen object contains information about the user's screen (monitor). It’s useful when you want to get details like screen resolution or color depth.
Common Properties of window.screen
| Property | Description | Example Value |
|---|---|---|
screen.width | Total width of the screen in pixels | 1920 |
screen.height | Total height of the screen in pixels | 1080 |
screen.availWidth | Width of the screen excluding OS taskbars/docks | 1920 |
screen.availHeight | Height of the screen excluding OS taskbars/docks | 1040 |
screen.colorDepth | Color depth (bits per pixel) | 24 |
screen.pixelDepth | Pixel depth of the screen | 24 |
Example Usage
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);Use Cases
Detecting screen resolution to adjust layouts or graphics.
Determining color depth for image processing.
Checking available screen space for popup windows.
If you want, I can show how to use window.innerWidth and window.innerHeight for viewport size (browser window size) too!