본문 바로가기
javascript

if..else / if.. else if

by rami_ 2022. 2. 27.

if : 조건이 true인 경우 statement1 실행

if (condition) {
  //  block of code to be executed if the condition is true
}

 

if..else : 조건이 true인 경우 statement1 실행. false일 경우 statement2실행

if (condition) {
  //  block of code to be executed if the condition is true
} else {
  //  block of code to be executed if the condition is false
}

 

if..else if : 조건1이 true인 경우 statement1실행. 조건1이 false이고 조건2가 true인 경우 실행

if (condition1) {
  //  block of code to be executed if condition1 is true
} else if (condition2) {
  //  block of code to be executed if the condition1 is false and condition2 is true
} else {
  //  block of code to be executed if the condition1 is false and condition2 is false
}

출처: W3C school(https://www.w3schools.com/js/js_if_else.asp)

'javascript' 카테고리의 다른 글

new 연산자  (0) 2022.02.27
Prototype method vs Object method  (0) 2022.02.27
Early Return  (0) 2022.02.27
Tree / Binary Search Tree  (0) 2022.02.26
this  (0) 2022.02.16