JavaScript
-
[javascript] 비교연산자 == 와 === 의 차이카테고리 없음 2020. 5. 27. 15:30
비교 연산자는 두 개의 값을 비교하여 true와 false결과값을 반환합니다. 비교 연산자의 종류에는 값이 동등한 지 비교하는 일치 연산자와 값의 간계를 비교하는 관계 연산자가 있다. 동등 연산자( == ) == 는 비교 대상 값의 자료형이 서로 다르면 강제로 형을 바꾼 뒤에 비교한다 이는 값의 자료형과 상관없이, 내용이 같은 경우 참(true)을 반환한다. 만약 두 값이 객체형이라면 메모리 주소를 바라보는지 확인한다. 일치 연산자( === ) 엄격한 기준을 가지고 있는 일치 연산자는 값의 내용을 비교하는 것뿐만 아니라, 자료형까지 일치하는지 비교한다. 동등 연산자처럼 자료형을 임의로 변환하지 않는다. 예시 더보기 console.log(5 == 5); console.log(5 == "5"); consol..
-
[javascript] 숫자형에 대해서 (Infinity, NaN)Front-end/Javascript 2020. 5. 27. 14:45
자바스크립트에서 숫자형(Number)이란 숫자 형태를 가진 데이터를 의미한다. 정수, 부동소수점, 작은 수, 큰 수등 여러유형의 숫자를 숫자형(Number) 하나로 정의한다. 이외에도 자바스크립트에서는 Infinity , NaN 값이 있다. 앞으로 나올 내용은 Infinity, NaN에 더 중점을 두어 포스팅할 예정이다. Infinity 말 그대로 무한대의 숫자형을 말한다. ECMA Script3 까지는 이 변수들의 값을 수정할 수 있었지만 ES5부터 수정할 수 없는 읽기 전용 상수로 바뀌었다. 더보기 console.log(Infinity); console.log(1 / Infinity); + Infinity로 나누면 무슨 값이든 0이 된다. 결과값 더보기 Infinity 0 NaN 'Not a Numb..
-
[javascript] hasOwnProperty를 통해 객체안에 속성여부 확인Front-end/Javascript 2020. 5. 26. 14:18
EX-1) var store = {snack:1000, flower:5000, beverage:2000}; for (var item in store){ if(!store.hasOwnProperty(item)) continue; console.log(item + ' 는 가격이'+store[item]+' 입니다.') } 위 코드는 store 객체를 순환하는 for - in 반복문 이다. 매 반복마다 hasOwnProperty를 이용하여 store 객체에 item 키 정보가 있는지 확인한다. 없으면 continue(계속진행) 를 통해 아래 코드는 실행하지않고 다음 순서로 넘어간다. 결과값 snack 는 가격이1000 입니다. flower 는 가격이5000 입니다. beverage 는 가격이2000 입니다. *..