How to use local variable as global [duplicate]

I have been working with some coordinates.Now I need to use x and y out of this function. This is code from w3schools but I have something like this.

<style>
div {
width: 200px;
height: 100px;
border: 1px solid black;
}
</style>

<div onmousemove="myFunction(event)"></div>

<p id="demo"></p>

<script>
function myFunction(e) {
  var x = e.clientX;
  var y = e.clientY;
  var coor = "Coordinates: (" + x + "," + y + ")";
  document.getElementById("demo").innerHTML = coor;
}

Just declare the variables outside the function:

var x=0, y=0;
function myFunction(e) {
  x = e.clientX;
  y = e.clientY;
  var coor = "Coordinates: (" + x + "," + y + ")";
  document.getElementById("demo").innerHTML = coor;
}