- Try to explain the most important objects of BOM?
window:浏览器中的 全局对象,代表整个浏览器窗口或标签页;
location:代表当前页面的 URL 和导航能力,可以用于读取、跳转或刷新页面
screen:包含显示屏相关信息,如分辨率、颜色深度、可用空间等 。
history:提供对浏览器会话历史的控制,如后退、前进、跳转等功能
navigator:包含浏览器和用户代理相关信息,如类型、版本、语言、在线状态等
- Try to explain the difference between window and document object.
window 对象:代表整个浏览器窗口(或标签页);它是顶层的全局对象
document 对象:是 window 下的属性,代表网页内容本身,即解析后的 DOM 树根节点。
- Try to explain the difference between setInterval() and setTimeout().
setTimeout(function, delay):在指定延迟(毫秒)后执行一次函数。它只执行一次,适用于延迟执行场景
setInterval(function, delay):每隔指定间隔重复执行函数,适用于不断执行的定时任务