Using Logical OR (||) for Default Values in Javascript


Use || to provide a default value if the first value is falsy.

Source Code

let userName = null;
let displayName = userName || 'Guest';
console.log(displayName);
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments