Skip to content

Instantly share code, notes, and snippets.

@alecat88
Created March 2, 2022 00:05
Show Gist options
  • Save alecat88/e7f9cebccfaa9b49ffa88bd47e38a552 to your computer and use it in GitHub Desktop.
Save alecat88/e7f9cebccfaa9b49ffa88bd47e38a552 to your computer and use it in GitHub Desktop.
ES12
// In the example, the ||= will check if the songsCount is false (0).
// If false, then the right value will be assigned to the left variable.
let myPlaylist = {songsCount: 0, songs:[]};
myPlaylist.songsCount ||= 100;
console.log(myPlaylist); // This will print: {songsCount: 100, songs: Array(0)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment