0

What is the difference if I pass the parameter to the function of the event or not, because if I do not put it, it will do the same job if I put the parameter Examples

let btn = document.getElementById("btn");
let p = document.getElementById("p");

function draw(x, y) {
    let div = document.createElement("div");
    div.innerText = 'x';
    div.style.position = 'absolute';
    div.style.top = y + 'px';
    div.style.left = x + 'px';
    document.body.append(div);
}

document.body.onclick = funcation(event){
    draw(event.clientX, event.clientY)
}

document.body.onclick = function () {
    console.log(event.clientX, event.clientY)
}
Nick is tired
  • 6,860
  • 20
  • 39
  • 51
Shaimaa
  • 13
  • 2
  • [Is event a global variable that is accessible everywhere inside the callback chain?](https://stackoverflow.com/q/6426497) | [Why is 'event' available globally in Chrome but not FF?](https://stackoverflow.com/q/30159017) | [Get calling Event inside of Class-Function without Parameter in JavaScript](https://stackoverflow.com/q/68854376) – VLAZ Jan 28 '22 at 15:48
  • thank you, Can I ask something, how can you give me same Qusstion ? – Shaimaa Jan 28 '22 at 15:56

0 Answers0