Learn Basic String and Array Methods by Building a Music Player - Step 74

Tell us what’s happening:

I’m a long time C# (.net) programmer, and the following statement confuses me:
const song = userData?.currentSong || userData?.songs[0];
It seems like to me that this should end up with song being set to true all the time unless userData is null. How does this work out that the song variable gets assigned as a song?

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region

const setPlayButtonAccessibleText = () => {
  const song = userData?.currentSong || userData?.songs[0];
  
};

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0

Challenge Information:

Learn Basic String and Array Methods by Building a Music Player - Step 74

the OR operator checks the first value, if it’s truthy it returns that, otherwise it returns the second operand. There is no conversion to a boolean.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.