mercredi 16 juin 2021

What type of IF statement is this? [duplicate]

I am a beginner and previously asked a question on Stack Overflow regarding a tutorial that I am attempting. I received an answer, however, I don't understand this IF statement, nor have I ever seen it before. I attempted to add Else IFs and Else but it doesn't work. Can somebody please help this newbie understand what this IF statement is doing?

let overlay;
document.querySelectorAll('#product-a, #product-b, #product-c').forEach(function(path) {
  path.onclick = chooseProduct;
})

function chooseProduct(e) {
  if (overlay) overlay.classList.remove('highlight')
  overlay = e.target
  overlay.classList.add('highlight')
}

Aucun commentaire:

Enregistrer un commentaire