if ?三元 ? 还是逻辑中断?

122 阅读1分钟

始于 if ,陷于三元,醉于逻辑中断,这次第,怎一个“妙”字了得!

if 语句:一个萝卜一个坑

const state = history.location.state
if (state) {
    history.replace(state.from)
} else {
    history.replace('/home')
}

三元表达式:一真二假

const state = history.location.state
history.replace(state ? state.from : '/home')

逻辑中断:逻辑与找假,逻辑或找真

const state = history.location.state
history.replace((state && state.from) || '/home')