← Back to JavaScript Course | Chapter 11: Browser Object Model | Lesson 2 of 6

JS Screen ऑब्जेक्ट

window.screen आपकी window जिस दीवार पर लगी है उसके dimensions जांचने जैसा है, window को नहीं, यह पूरे display के बारे में बताता है, सिर्फ browser के visible area के बारे में नहीं।
Syntax
javascript
screen.width;
screen.height;
screen.availWidth;

Screen Object क्या है?

window.screen user के physical display device के बारे में जानकारी देता है, इससे independent कि browser window फिलहाल कितनी बड़ी है। यह hardware/display facts का एक read-only source है, कोई ऐसी चीज़ नहीं जिसे आप configure करें।

उदाहरण: What Is the Screen Object?

javascript
console.log(screen.width, screen.height); // physical display resolution

Screen Size Properties

screen.width और screen.height display का पूरा resolution pixels में बताते हैं, जबकि screen.availWidth और screen.availHeight taskbar या dock जैसे OS elements द्वारा ली गई जगह घटा देते हैं।

available values आमतौर पर layout decisions के लिए ज़्यादा उपयोगी होती हैं।

उदाहरण: Screen Size Properties

javascript
console.log(screen.width, screen.height); // full resolution
console.log(screen.availWidth, screen.availHeight); // minus OS taskbar/dock

Color और Pixel Depth

screen.colorDepth और screen.pixelDepth बताते हैं कि प्रति pixel रंग represent करने के लिए कितने bits इस्तेमाल होते हैं, modern hardware पर लगभग हमेशा 24 या 30।

यह आज शायद ही कभी इस्तेमाल होता है पर specialized graphics या display capability जांचने वाली accessibility tooling के लिए मायने रखता है।

उदाहरण: Color and Pixel Depth

javascript
console.log(screen.colorDepth, screen.pixelDepth);

Screen बनाम Window Dimensions

यह एक आम गलती है: screen.width monitor का कुल resolution है, जबकि window.innerWidth browser viewport size है, जो लगभग हमेशा छोटा होता है।

दोनों को मिला देना ऐसा layout code देता है जो maximized window पर सही व्यवहार करता है पर user के resize करते ही टूट जाता है।

उदाहरण: Screen vs Window Dimensions

javascript
console.log("Screen:", screen.width, "x", screen.height); // monitor resolution
console.log("Window:", window.innerWidth, "x", window.innerHeight); // browser viewport, usually smaller

Practical Uses

Screen properties मुख्यतः ऐसे adaptive experiences के लिए इस्तेमाल होती हैं जो physical display की परवाह करते हैं, जैसे किसी high colorDepth screen के लिए एक higher-resolution image set चुनना, available screen space के relative एक popup size खोलना, या visitor display sizes के बारे में basic analytics।

उदाहरण: Practical Uses

javascript
// Check whether `screen.colorDepth >= 24`
// Check whether `screen.colorDepth >= 24`
if (screen.colorDepth >= 24) {
  // Print "Load high-resolution images" to the console
  // Print "Load high-resolution images" to the console
  console.log("Load high-resolution images");
// Otherwise, run this branch
// Otherwise, run this branch
} else {
  // Print "Load standard images" to the console
  // Print "Load standard images" to the console
  console.log("Load standard images");
}
Live Example
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. page की width के लिए screen.width इस्तेमाल करना, जबकि यह पूरा monitor होता है; viewport के लिए window.innerWidth इस्तेमाल करें।
  2. यह मान लेना कि high-DPI displays पर screen values real pixels में होती हैं, जबकि वे CSS pixels हैं।
  3. phones detect करने के लिए screen size पर निर्भर रहना, जबकि media queries या feature checks बेहतर हैं।
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.