Window - window.screen
With window.screen
, you can know how the user's screen is visually composed.
It is mainly used when you want to know the size or resolution of the current screen or the device in use.
Key Properties
-
screen.width
: The total width of the screen (in pixels) -
screen.height
: The total height of the screen (in pixels) -
screen.availWidth
: The width of the available screen space excluding browser UI -
screen.availHeight
: The height of the available screen space excluding browser UI
Examples
Checking the width and height of the screen
JavaScript
console.log(`The width of the screen is ${screen.width} pixels.`);
console.log(`The height of the screen is ${screen.height} pixels.`);
Checking the available screen size
JavaScript
console.log(`The available width of the screen is ${screen.availWidth} pixels.`);
console.log(`The available height of the screen is ${screen.availHeight} pixels.`);
Want to learn more?
Join CodeFriends Plus membership or enroll in a course to start your journey.