how to extract a javascript variable from a function

I want to retrieve the variable x from the function, but this code does not work
who has an idea

thank you

function myFunction(){
  var x = document.getElementById("nom").value;
  //document.getElementById("demo").innerHTML =x ;

 return x;
}

response = myFunction();

document.getElementById("deux").innerHTML =response ;