Hey guys! I’ve just finished my Palindrome Checker project, but I still have a hard time understanding the music player project, which is so much more difficult than the rest of the lessons so far…
playButton.addEventListener("click", () => {
if (userData?.currentSong === null) {
playSong(userData?.songs[0].id);
} else {
playSong(userData?.currentSong.id);
}
One of the things that confused me with the code above was after the “click”… what does “() => {}” exactly ? I learned from the project how to create functions with () => {}, but I don’t think this is it… Can someone help explaining what () => {} does in an addEventListener ? because it keeps coming up in later projects…
Also, in the case above, why not just call for the playSong function like
“playButton.addEventListener(“click”, playSong)”
and input the “if” and “else” when we created the playSong function ?
Thanks for any input!