Understanding Default Values with Logical OR (||) in Javascript


Use the logical OR operator to set default values.

Source Code

let name = "";
let defaultName = name || "John Doe";
console.log(defaultName); // "John Doe"
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments