
웹 브라우저의 주요 구성 요소는 필수적인 객체들로 구성. 이들은 브라우저의 기능을 활용하는 데 중요한 역할. 구성 요소들은 크게 BOM과 DOM으로 구분. 둘 다 window 객체와 밀접하게 연관

BOM은 브라우저 환경에서 제공하는 여러 객체를 포함하여 웹 페이지와 브라우저 간의 상호작용을 가능하게 함. 이 구성의 핵심은 window 객체로, 브라우저 창을 나타내며 다양한 기능에 접근 가능
⚠️ window 객체는 브라우저 전용이므로 HTML 환경에서 실행 필요
DOM은 HTML 문서의 구조를 객체로 표현하여 JavaScript로 문서를 동적으로 조작 가능. DOM은 사실 BOM의 일부로 볼 수 있으나, 그 크기와 중요성 때문에 별도로 취급
사실 DOM도 BOM의 하위집합이지만, 그 규모가 크기 때문에 BOM과 DOM으로 나누어 구분
alert()alert("안녕하세요!"); // 경고창 표시
setTimeout()setTimeout(() => console.log("3초 후 실행"), 3000);
setInterval()clearInterval()로 중지 가능let count = 0;
const id = setInterval(() => {
console.log(count++);
if (count > 5) clearInterval(id);
}, 1000);
confirm()true, 취소 시 false를 반환const result = confirm("계속하시겠습니까?");
console.log(result ? "계속" : "취소");
prompt()null을 반환const name = prompt("이름을 입력하세요:");
if (name) console.log(`안녕하세요, ${name}님!`);
innerWidth, innerHeightconsole.log("너비:", window.innerWidth, "높이:", window.innerHeight);
window.addEventListener('resize', () => {
console.log("변경된 창 너비:", window.innerWidth);
});
location 객체는 현재 문서의 URL 정보를 제공하고 조작할 수 있는 중요한 BOM 객체
location.hrefconsole.log(location.href); // 현재 URL 출력
location.href = "https://www.example.com"; // 페이지 이동
location.reload()true를 전달하면 캐시를 무시하고 서버에서 다시 로드location.reload(true); // 서버에서 다시 로드
location.replace()location.replace("https://www.newsite.com");
location.hostnameconsole.log(location.hostname);
navigator 객체는 브라우저와 운영 체제의 정보를 제공
navigator.userAgentconsole.log(navigator.userAgent);
// 출력예) "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
Screen 객체는 사용자의 화면 정보를 제공. 픽셀 크기, 색상 깊이 등의 정보를 통해 사용자 환경에 맞춘 웹 페이지를 구성할 때 유용
console.log("화면 너비:", screen.width, "화면 높이:", screen.height);
출처: 수코딩