स्टैटिक प्रॉपर्टीज क्लास फ़ंक्शन को ही असाइन की जाती हैं न कि इसकी प्रोटोटाइप प्रॉपर्टी को। इन प्रॉपर्टीज को बिना किसी ऑब्जेक्ट को इंस्टेंशिएट किए सीधे कॉल किया जा सकता है।
जावास्क्रिप्ट में स्टैटिक प्रॉपर्टीज का कोड निम्नलिखित है -
उदाहरण
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 20px; font-weight: 500; color: blueviolet; } </style> </head> <body> <h1>जावास्क्रिप्ट में स्टैटिक प्रॉपर्टीज</h1> <div class="result"></div> <button class="Btn">यहाँ क्लिक करें</button> <h3>Student की स्टैटिक प्रॉपर्टी school को एक्सेस करने के लिए ऊपर दिए गए बटन पर क्लिक करें</h3> <script> let resEle = document.querySelector(".result"); function Student(name, age) { this.name = name; this.age = age; } Student.school = "St Marks Public School"; document.querySelector(".Btn").addEventListener("click", () => { resEle.innerHTML = "Student.school = " + Student.school; }); </script> </body> </html>
आउटपुट

'यहाँ क्लिक करें' बटन पर क्लिक करने पर -
