Answers for "handling null values using ternary operator"

0

handling null values using ternary operator

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"
Posted by: Guest on June-19-2021

Browse Popular Code Answers by Language