써치킴의 우당탕탕 개발 블로그

[JavaScript][Ch9] JS 조건문 본문

파도파도 나오는 JavaScript

[JavaScript][Ch9] JS 조건문

써치킴 2022. 1. 6. 06:53

조건문

조건의 결과(truthy, falsy)에 따라 다른 코드를 실행하는 구문

if, else

 

if

let isShow = true;
let checked = false;

// 조건 구문
if (isShow) {   // 조건 -> 참(true)  
  console.log('show');    // show
}
// 조건 구문
if (isShow) {   // 조건 -> 거짓(false)  
  console.log('cheked'); 
}

 

if~else

let isShow = true;

// 조건 구문
if (isShow) {   // 조건이 참이면  
  console.log('show');    // show
} else {        // 조건이 참이 아니면
  console.log('hide'); 
}
Comments