true && 'hello' // 'hello'
false && 'hello' // false
true || 'hello' // true
false || 'hello' // 'hello'
const elem = null
const value = elem?.length
console.log(value) // undefined
?? 연산자를 기준으로 좌항이 null 혹은 undeifned 일 경우 우항을 반환하고, 그렇지 않으면 좌항을 반환한다.
const name = null ?? 'shelly'
console.log(name) // shelly
true ?? 'shelly' // true
true || 'shelly' // true
false ?? 'shelly' // false
false || 'shelly' // 'shelly'
1 ?? 'shelly' // 1
1 || 'shelly' // 1
0 ?? 'shelly' // 0
0 || 'shelly' // 'shelly'
null ?? 'shelly' // 'shelly'
null || 'shelly' // 'shelly'
undefined ?? 'shelly' // 'shelly'
undefined || 'shelly' // 'shelly'
'' ?? 'shelly' // ''
'' || 'shelly' // 'shelly'
NaN ?? 'shelly' // NaN
NaN || 'shelly' // 'shelly'
[] ?? 'shelly' // []
[] || 'shelly' // 'shelly'
({}) ?? 'shelly' // {}
({}) || 'shelly' // {}
const obj = {dog : 'happy'}
const dogName = obj?.dog ?? 'cookie' // 'happy'
const catName = obj?.cat ?? 'nabi' //
const { status } = await api() // { status : 200}
if (status === 200) {
console.log('success')
}
const { status } = await api() // { status : 200}
status === 200 && console.log('success')