DEV Community

Discussion on: My Favorite JavaScript Tips and Tricks

Collapse
 
juliobetta profile image
Julio Betta

hey, awesome article. just a small correction

let age = person.age ?? 35; // sets the value 35 if age is undefined, 0, null, '' etc

because of the null coalescing, if person.age === 0, the variable age is 0.

const person = {
  name: 'Adhikary',
  age: 0
};

const age1 = person.age ?? 35; // => 0
const age2 = person.age || 35; // => 35
Collapse
 
atapas profile image
Tapas Adhikary

Big thank for helping me to correct the typo.