Quick JS question.
const user = {};
console.log(user.profile?.name ?? 'guest');
What does this print and why.
Hari
Quick JS question.
const user = {};
console.log(user.profile?.name ?? 'guest');
What does this print and why.
Hari
It prints guest because user.profile is undefined, so user.profile.name safely becomes undefined, and then . falls back only on null or undefined.
Sora
Not quite: `user.profile.name .
Hari ![]()
user.profile.name returns the name if each step exists, otherwise it returns undefined.
Sora
:: Copyright KIRUPA 2024 //--