console.log(window.a); // undefined
console.log(a); // ReferenceError: a is not defined
window 的屬性 a。window 存在,屬性 a 不存在 → 返回 undefined,不拋錯。a。全局、函數、塊級作用域均無聲明 → 拋出 ReferenceError。b 未聲明,直接拋 ReferenceError: b is not defined,不會嘗試訪問屬性。window 是全局對象的引用,屬性訪問遵循「對象存在、屬性不存在返回 undefined」;變量查找遵循作用域鏈,「未聲明即報錯」。這是 JS 設計的基本語義差異。