My issue here is not passing the challenge, but rather the note included in the instruction:
Namely, “[y]ou should not use the optional chaining operator ?. in this step because userData.currentSong will not be null or undefined at this point.”
But what if the user has not yet selected a song? Wouldn’t userData.currentSong be null in that case?
What am I missing here?
Thank you for your help!
Challenge Information:
Learn Basic String and Array Methods by Building a Music Player - Step 40
It is exactly in this assigning you are pointing to , namely userData.currentSong = song;, where I feel like I’m missing something.
My understanding is that the expression userData.currentSong accesses the currentSong property of the userData object I have declared earlier in the code like so:
If the user has just begun their session and selects a song, userData.currentSong will be assigned the current song for the first time at which point the value is still null, is it not? I see that it will have a value (other than null) after this step, but not before (and during) the assigning itself, right?
you are assigning song to an existing property, so you don’t need to worry about the previous value of userData.currentSong, you are assinging to it
I don’t even understand why the optional chaining note is there, it’s quite confusing