본문 바로가기

프론트엔드 공부/javscript

삼항연산자

const grade =55;
const result = 
(grade>80)?'distingction'
:(grade>50) ? 'pass' : 'fail';

console.log(result)//pass

if / else 문을 대체하는 삼항연산자가 return을 여러 번 사용하고 if 블록 내부에서 한줄만 나올때 return을 대체 할 수 있음. if else if else 구문으로도 작성 가능 

 

developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Operators/Conditional_Operator

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

array.includes  (0) 2021.04.29
단축평가값(circuite evaluation)  (0) 2021.04.29
배열구조분해할당(destructing)  (0) 2021.04.29
객체구조분해할당(destructing) 예시  (0) 2021.04.28
switch 열거문  (0) 2021.04.28