Javascript Music Player Step 43 - Possible unnecessary use of optional chaining

Step 43 asks you to pass userData?.songs[0].id as an argument to playSong. I don’t think that optional chaining is a good thing to do here, because the function playSong assumes that a song id is passed to it and has no handling in case something else is passed. I feel that any handling of the edge case where the .songs property doesn’t exist should happen in the callback function to the playButton’s event Listener.

This step might accidentally teach more inexperienced learners to spam optional chaining even where it doesn’t make sense or might even make debugging more difficult.

Would love to hear thoughts on this.

Same with Step 44 - the else block is designed on the assumption that .currentSong property exists, but the step requires userData?.currentSong.id to pass. This looks wrong to me.

your concern may be relevant to this issue on github, if yes, please feel free to add your comments there

Thanks for the reply :slight_smile:
I agree that with your view that there are a lot of places in this project where optional chaining isn’t really needed. I don’t think I have anything new to add to the topic though. Addressing this will need quite a few big changes to the curriculum.

okay. If you have thoughts to add to the issue, please feel free to do it there.
thanks

1 Like

luckily, big changes to the curriculum is what is being worked on. See the banner at the top of the forum

You’re right, other types of chaining are helpful. But sometimes it is overused when simpler logic would suffice. Changing the curriculum to address this issue would certainly be a big deal. But it’s worth considering cleaner code and better learning outcomes. Thank you for your understanding on this topic!

hi Ilenia,

I can’t see a banner at this time?


it’s there

1 Like

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