DEV Community

Discussion on: My Favorite JavaScript Tips and Tricks

Collapse
 
atapas profile image
Tapas Adhikary

Which browser are you using? It should work.

let person = {name: 'Jack'};
let age = person.age ?? 35; // sets the value 0 if age 0, 35 in case of undefined and null
console.log(`Age of ${person.name} is ${age}`);
Enter fullscreen mode Exit fullscreen mode

Output, Age of Jack is 35

Also, check if there is a syntax error. You can paste the code as a comment.