if I use arrow function instead of normal function flip and do add addeventlistiner to it before initializing the arrow function then I am not able to call the function.
**
Not Working
console.log(cards); cards.forEach((card) => card.addEventListener("click",flip)); var flip = ()=>{ console.log("card flipped"); }
output : on clicking of the card it should give me the output as "card flipped", but it does not do anything.
- Working
var flip = ()=>{
console.log("card flipped"); }
const cards = document.querySelectorAll(".card");
console.log(cards);
cards.forEach((card) =>
card.addEventListener("click",flip));
output : on clicking of the card it is giving me the output as "card flipped",
How do I call the arrow function before initializing it ?