자바스크립트는 단지 html와 css를 바꾸고 싶어서 만들어지지 않았다.

이벤트에 반응하기 위해서 만들어 졌다.

이벤트는 웹사이트에서 발생하는 것들을 말한다.(click residze submit input change load before closing printing 등)

 

const title = document.qeurySeletor("#title");

function handleResize(){
	console.log("I have been resized")
}

window.addEventListener("resize", handleResize);

window resize는 handleResize를 호줄한다.

handleResize(); 를 적으면 함수를 바로 호출한다.

 

이벤트 예시

const title = document.qeurySeletor(#"title");

function handleResize(event){
	console.log(event)
}

window.addEventListener("resize", handleResize);

이벤트가 발생할 때 마다 호출된다.

 

클릭할때 색상변경 예시

const title = document.querySelector("#title");

function handleClick(){
title.style.color = "blue";
}

title.addEventListener("click", handleClick);