2-27 / 3-1 / 3-2 / 3-3 / 3-4 / 3-5 / 3-6 / 3-7
- 객체의 성질에 대한 나의 이해방식
- 똑같이 생긴 것을 같다고 하면, false가 나옴 -> 객체는 똑같이 생겨도, 따로 만들어짐
- 변수 a에 객체를 넣고, b에 a를 넣으면, b와 a는 연결이 되어서, a만 수정해도, b도 바뀐다.
const a = {name: 'zeroCho',};
const b = a;
a.name='hero';
a === b;
true;
let a = 'zeroCho';
let b = a;
a ='hero';
a === b;
false;
값을 입력 받는 창
경고창
확인, 취소 창
document.querySelector('input');
document.querySelectorAll('button');
document.querySelector('#word');
document.querySelector('.btn');
document.querySelectorAll('.btn');
document.querySelector('div > span');
document.querySelector('div p');
<div>
<span>
<p></p>
</span>
</div>
document.querySelectorAll('button');
console에 입력document.querySelector('button').addEventListener('click',function(){});
.addEventListener('click',function(){console.log('클릭')});
- 버튼 클릭을 감지한다. -> console.log('클릭') 실행
- 이때 이벤트를 감지 후에 실행되는 함수는
콜백 함수 또는 리스너 함수
라고 불린다.
document.querySelector('input').addEventListener('input',function(event){console.log('글자입력',event.target.value)});
- input tag의 글자 입력을 감지한다.
- 어떤 글자가 입력되었는지 확인할 수 있다
const onClick = function(){console.log('클릭')}; document.querySelector('button').addEventListener('click',onClick);
- 콜백함수를 밖에서 만들고 넣을 수 있다.
- 주의할 점 : 변수 선언문 형태로 만들었을 때, 콜백함수에 ()를 붙이면 안된다.
개념
!변수명
조건문에 응용하기
let word;
if(!변수명){}
변수에 저장된 값이 없을 때, 조건문을 만들 수 있다.
<span id="order">1</span>번째 참가자
let word; //input에 입력된 단어를 저장하기 위한 변수
let $input = document.querySelector('input'); //input tag를 가지고 와서 변수에 저장함
$input.addEventListener('input',onInput); //input tag에 입력(input)될 때, 감지해서 함수실행시킴
const onInput = function(event) { // **핵심** 입력된 값을 변수에 저장시킴;
word = event.target.value;
};