Global Object khác với các object thường. Không thể tạo bằng new. Nó tồn tại khi scripting engine được khởi tạo. Sau khi init, các hàm và hằng số built-in sẵn sàng dùng.
Global Object cho phép:
- Truy cập built-in functions/values trực tiếp hoặc qua
window:alert("Demo")hoặcwindow.alert("Demo"). - Truy cập biến global (var) và function declaration:
window.str.
<html>
<head>
<script>
var str = "Demo Text";
// dùng window
alert(window.str);
</script>
</head>
<body>
</body>
</html>