Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alecat88/67be5b81b89907d85ceb77f40c564acd to your computer and use it in GitHub Desktop.
Save alecat88/67be5b81b89907d85ceb77f40c564acd to your computer and use it in GitHub Desktop.
ES12
// In the example, the ??= will check if the lastname is null or undefined.
// If null or undefined, then the right value will be assigned to the left variable.
let userDetails = {firstname: 'Katina', age: 24}
userDetails.lastname ??= 'Dawson';
console.log(userDetails); // This will print: {firstname: 'Katina', age: 24, lastname: 'Dawson'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment