- JS Introduction
- JS Introduction
- JS Comments
- JS Variables
- JS Datatypes
- JS Operators
- JS Type Conversions
- JS Control Flow
- JS Comparisons
- JS If else
- JS If else Ladder
- JS Ternary Operator
- JS Switch
- JS For Loop
- JS For In
- JS For Of
- JS While
- JS Do While
- JS Break & Continue
- JS Functions
- JS Function Declaration
- JS Function Parameters
- JS Return Statement
- JS Function Expressions
- JS Anonymous Functions
- JS Objects
- JS Objects
- JS Object Methods
- JS Object Constructors
- JS Object Destructuring
- JS Object Prototypes
- JS Map, Filter & Reduce
- JS ES6
- JS ES6
- JS let and const
- JS Arrow Functions
- JS Template Literals
- Destructuring Assignment
- JS Spread Operator
- JS Default Parameters
- JS Classes
- JS Inheritance
- JS Map
- JS Set
- JS Async
- JS Callbacks
- JS Asynchronous
- JS Promises
- JS Async/Await
- JS HTML DOM/BOM
- JS Document Object
- JS getElementbyId
- getElementsByClassName
- JS getElementsByName
- getElementsByTagName
- JS innerHTML
- JS outerHTML
- JS Window Object
- JS History Object
- JS Navigator Object
- JS Screen Object
JavaScript Screen Object
Accessing the Screen Object:
- The screen object is a property of the global window object in the browser environment.
- You can access it directly via window.screen.
Screen Dimensions:
- Properties like width and height provide the dimensions of the user's screen in pixels.
Example: Accessing Screen Dimensions
console.log(screen.width); // Returns the width of the screen in pixels
console.log(screen.height); // Returns the height of the screen in pixels
Screen Pixel Depth:
- The pixelDepth property indicates the color depth of the screen, i.e., the number of bits used to represent the color of a single pixel.
Example: Accessing Screen Pixel Depth
console.log(screen.pixelDepth); // Returns the color depth of the screen
Screen Orientation:
- The orientation property provides information about the screen's orientation, such as whether it's in landscape or portrait mode.
Example: Accessing Screen Orientation
console.log(screen.orientation.type); // Returns the screen orientation type ('landscape-primary', 'portrait-primary', etc.)
Screen Availablity:
- The availWidth and availHeight properties represent the available width and height of the screen after subtracting space occupied by taskbars and other UI elements.
Example: Accessing Available Screen Dimensions
console.log(screen.availWidth); // Returns the available width of the screen in pixels
console.log(screen.availHeight); // Returns the available height of the screen in pixels
DPI and Pixel Ratio:
- While not directly provided by the screen object, you can calculate the screen's DPI (dots per inch) and pixel ratio using the screen's dimensions and physical size.
Key Points
- The screen object in JavaScript provides information about the user's screen and its display capabilities.
- It includes properties to access screen dimensions, pixel depth, orientation, and available screen space.
- Understanding the screen object is useful for developing web applications that need to adapt their layout or behavior based on the user's screen size and capabilitie.