WEB UIUX/javaScript

[javaScript]자바스크립트 삼항조건연산자

카이아 2022. 10. 19. 14:28

# 삼항조건연산자

- 삼항조건연산자는 조건식(true, false의 결과값 반환)
=> 반환의 결과에 따라 실행 결과가 달라진다.
- 결과값이 true이면 = 질문?을 던져서 A : B;(A이냐 B이냐) 에서 A를 실행 
- 결과값이 false이면 = 질문?을 던져서 A : B; 에서 B를 실행 

 

const a = 10;
const b = 3;

const result = a < b? "javaScript" : "jQuary"; //?로 질문
document.write(result, "<br>"); //jQuary (false값이다.)

const webdesign = a > b? "Illustrator" : "Photoshop";
document.write(webdesign, "<br>"); //Illustrator (true값이다.)

const mathScore = a == b? "100점" : "50점";
document.write(mathScore, "<br>"); //Illustrator (true값이다.)

 

 

See the Pen [js]삼항조건연산자 by kaia (@kaiaakim) on CodePen.