1

I tried to use the event.clientX outside of window function. But it says xAxis is not defined. Can have an way to get it? My code below,

window.onclick = function(event) {
        let xAxis = event.clientX;
}
alert(xAxis);
  • If you declare the variable (with `let xAxis`) inside the function, then you can't access it outside that function … and if you resolve that then you can't put an `alert` immediately after some code which says "**when the user clicks** on something run this function" and expect that function to have run **before** the `alert` is reached. – Quentin Sep 04 '22 at 08:28

0 Answers0