📜  使用三元运算符处理空值 - 任何代码示例

📅  最后修改于: 2022-03-11 15:00:22.787000             🧑  作者: Mango

代码示例1
let greeting = person => {
    let name = person ? person.name : `stranger`
    return `Howdy, ${name}`
}

console.log(greeting({name: `Alice`}));  // "Howdy, Alice"
console.log(greeting(null));             // "Howdy, stranger"