
DOM과 조건문 const title = document.getElementById("title"); const BASE_COLOR = "red"; const OTHER_COLOR = "blue"; function handleClick(){ const currentColor = title.style.color; if(currentColor === BASE_COLOR){ title.style.color = OTHER_COLOR; } else { title.style.color = BASE_COLOR; } console.log(currentColor); } function init(){ title.style.color = BASE_COLOR; title.addEventListener("click", hand..

1. 함수 호출하기. 이 때 `(백틱)을 사용하여 깔끔한 문장을 구사하였다. function sayHello(name, age) { return `Hello ${name} you are ${age} years old`; } const greeting = sayHello("park", 30); console.log(greeting); // Hello park you are 30 years old 2. 계산기. 이 때 calculator는 Object이고, plus는 함수이다. const calculator = { plus: function(a, b){ return a+b; }, minus: function(a, b){ return a-b; }, times: function(a, b){ return a*b;..

조건문 특정 조건 만족 시(참인 경우) 실행하는 명령의 집합 이며, 어떤 작업을 수행하고 싶을 때 사용하는 것이 조건문이다. If-else If-else는 조건문이다. 조건에 따라 수행할 내용을 쓸 때 사용한다. 사용방법은 아래와 같다. if(10 > 5){ console.log("Hi"); }else{ console.log("ho"); } 조건식이 true일 경우 Hi, false 일 경우 Ho를 출력한다. 자바스크립트에서 같다와 같지않다의 표현 JS에서 조건문을 사용할 때 '같다'는 ===이고 '같지 않다'는 !== 이다. && 와 || &&는 and를 의미. 조건을 모두 충족할 때 ||는 or을 의미. 조건 중 하나를 충족할 때

Events Events란 웹사이트에서 발생하는 모든것들을 일컫는말 이다. 예를 들어 click,resize,submit,inputchange등등을 말할수있다.그리고 JavaScript는 이 이벤트를 중간에 가로챌 수 있다. 예시 1. 윈도우 창의 Resize 이벤트 function handleResize(){ console.log("I have been resized"); } window.addEventListener("resize", handleResize()); // handleResize 함수 자동 호출 window.addEventListener("resize", handleResize); // 원할 때 handleResize 호출 (resize event가 발생할 때)

DOM with JS [index.html] This works! [index.js] const title = document.getElementById("title"); title.innerHTML = "Hi from js"; // title의 내용이 바뀐다. console.dir(title); console.dir(title); console.dir(title); 를 입력하면 title객체의 property를 전부 확인 할수있다.