FrontEnd/Interviews

Javascript ==와 ===의 차이

SambaLim 2019. 11. 21. 23:12
JS_equality_operator

What is the difference between the equality operators == and ===?

동등연산자 =====의 차이는 무엇입니까?

 

나의 답변

JS에서 =====의 차이점은 ===은 비교대상의 자료형(type)까지 비교한다는 점입니다.

 

추가 학습내용

ECMAScript 표준에서는 7개의 자료형을 정의한다.

  1. Boolean
  2. Null
  3. Undefined
  4. Number
  5. String
  6. Symbol
  7. Object

 

=====의 차이점이 type까지 검사한다고 할 때, 쉽게 생각할 수 있는 오류는 기본타입(Primitive values)외의 타입에서 일어나기 쉽다.

Object의 경우 생성할 때, 각각 다른 메모리 주소를 할당받게 된다. 따라서 위의 예제에서 ab의 type은 Object로 같지만, 참조하는 메모리의 주소가 다르기 때문에 a === b의 결과는 false가 출력된다.

 

참고

https://developer.mozilla.org/ko/docs/Web/JavaScript/Data_structures

https://steemit.com/kr-dev/@cheonmr/js-operator

'FrontEnd > Interviews' 카테고리의 다른 글

React Element와 Component 차이  (0) 2019.11.24
CSS preprocessor 장점 단점  (0) 2019.11.20
Cache busting  (0) 2019.11.20
BEM (Block Element Modifier)  (0) 2019.11.19
alt 속성  (0) 2019.11.19