if...else, ? 연산자

장돌뱅이 ·2022년 1월 2일
0

JavaScript

목록 보기
6/46

- if...else

if (false) {
  console.log('The code in this block will not run.');
} else {
  console.log('But the code in this block will!');
}
 
// Prints: But the code in this block will!

() 안에 연산식을 넣는다.
if문에서 false 값을 넣으면 입력값은 실행되지 않고 else값이 실행된다.
(true일 때 if값이 실행됨)

- ? 연산자 (ternary operator)

조건 ? value1 : value 2;

조건이 true이면 ? 다음을 실행, 그게 아니면 : 다음을 실행

간단하게 출력 등이 필요할 때 사용

0개의 댓글

관련 채용 정보