velopert / learnjs

벨로퍼트와 함께하는 모던 자바스크립트
https://learnjs.vlpt.us/
85 stars 47 forks source link

03. 단축 평가 논리 계산법 · GitBook #22

Open utterances-bot opened 4 years ago

utterances-bot commented 4 years ago

03. 단축 평가 논리 계산법 · GitBook

https://learnjs.vlpt.us/useful/03-short-circuiting.html

AppleCEO commented 4 years ago

마지막에 A 가 Falsy 할 때 B 도 Falsy 하면 B 는 출력되지 않을 것 같은데 확인 부탁드립니다!

EunkyoungJung commented 3 years ago

테스트를 해봤는데, 0 == false // true '' == false // true

'' || 0 // 출력결과 0 0 || '' // 출력결과 ''

결론적으로, falsy || falsy이면 두번째 falsy가 출력되네요! 둘중에 하나로 참이면 참이기 때문에, 첫번째가 거짓이더라도 두번째가 참이면 참일 수 있어서, 두번째까지 확인하게 되어 있어서 그런 것 같습니다.

granen32 commented 3 years ago

20210308

Jibros commented 2 years ago

22.03.22

zuzubibi commented 2 years ago

22.03.25

serpiko-git commented 2 years ago
// (2022 추천해요) Optional chaining and Nullish coalescing operator :)
const nameWithDog = {
 name: '멍멍이'
};

function getName(animal) {
  return animal?.name ?? '이름이 없는 동물입니다.';
}

console.log( getName() ); // 이름이 없는 동물입니다.
console.log( getName(nameWithDog) ); // 멍멍이
JunghooX commented 2 years ago

22.08.18

daeunkim99 commented 2 months ago

240624