본문 바로가기

프론트엔드 공부/javscript

단축평가값(circuite evaluation)

const result = 0 || 40 || 60; 
console.log(result);//40 falsy truthy truthy

const result2 = 0 || '' || 60;
console.log(result2);//60

논리 연산자들은 왼쪽 > 오른쪽으로 실행됌.

이 연산자들은 결과를 얻게 되면 평가를 중단함.

and 연산자에서는 false를 첫번째로, or 연산자에서는 true를 첫번째로 작성하는 것이 유용함

'프론트엔드 공부 > javscript' 카테고리의 다른 글

array.every(function);array.some(function);  (0) 2021.04.29
array.includes  (0) 2021.04.29
삼항연산자  (0) 2021.04.29
배열구조분해할당(destructing)  (0) 2021.04.29
객체구조분해할당(destructing) 예시  (0) 2021.04.28