본문 바로가기

JS

(3)
toggle index.js 1 2 3 4 5 6 7 8 9 10 11 12 13 const title = document.querySelector("#title"); const CLICKED_CLASS = "clicked"; function handleClick() { title.classList.toggle(CLICKED_CLASS); } function init(){ title.addEventListener("click", handleClick); } init(); s 결과화면과 index.html입니다. 1 Work Work Work Work! cs id는 title로 주고 class는 btn으로 준 예시입니다. 1 2 3 4 5 6 7 8 9 10 11 12 const title = document.quer..
Javascript, window.addEventListener 1 2 3 4 5 function handleResize(){ console.log("I have been resized") } window.addEventListener("resize", handleResize); 1 2 3 4 5 function handleResize(){ console.log("I have been resized") } window.addEventListener("resize", handleResize()); 위와 아래는 5번라인 handleResize, handleResize() 인데 중요한 차이가 있다고 합니다. handleResize는 창 크기를 변화시킬때 발생하고 handleResize()는 실행과 동시에 발생합니다. 참고자료 : Nomade Coder
바닐라 JavaScript, function의 return 1 2 3 4 5 6 7 function sayHello(namem, number){ console.log(`Hello! ${name} your favNumber is ${number}. O_O;b`); } const greetDhkim = sayHello("dhkim", 112) console.log(greetdhkim) cs console창의 결과값 Hello! your favNumber is 112. O_O;b undefined 5번 라인의 결과 Hello! your favNumber is 112. O_O;b 7번 라인의 결과 undefined 5번은 변수 greetDhkim이 sayHello function에 인자값을 이용해 console.log가 실행되었고 7번은 return값을 넣어준게 아니라..