Static properties được gán trực tiếp cho class function chứ không phải cho prototype property của nó. Các property này có thể được gọi trực tiếp mà không cần khởi tạo bất kỳ đối tượng nào.
Dưới đây là mã về static properties trong JavaScript:
Ví dụ
<!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>Static Properties trong JavaScript</h1> <div class="result"></div> <button class="Btn">CLICK HERE</button> <h3>Nhấn nút trên để truy cập static property school của Student</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>
Kết quả

Khi nhấn nút 'CLICK HERE':
