const a = random() //import된 random 함수
if (a === 0) {
console.log('a is 0')
} else if (a === 2) {
console.log('a is 2')
} else {
console.log('rest...') // 나머지 매개변수
}
const a = 1 < 2
if a {
console.log('참')
} else {
console.log('거짓')
}
console.log(a ? '참' : '거짓')
if (a === 0) {
console.log('a is 0')
} else if (a === 2) {
console.log('a is 2')
} else if (a === 4) {
console.log('a is 4')
} else {
console.log('rest...')
}
// 위 조건문과 동일한 결과를 갖는 switch문
switch (a) {
case 0:
console.log('a is 0')
break
case 2:
console.log('a is 2')
break
case 4:
console.log('a is 4')
break
default: console.log('rest...')
}
for (시작조건; 종료조건; 변화조건) {}
for (let i = 0; i < 3; i += 1) {
console.log(i)
}
// 0, 1, 2
const ulEl = document.querySelector('ul')
for (let i = 0; i < 3; i += 1) {
const li = document.createElement('li')
li.textContent = `list-${i + 1}`
ulEl.appendChild(li)
}
출력 결과