I have the following code in js, which does not save the input information in the variable. At the time of activating the function show () it returns me that the variable x is not defined
function crear(){
var x = document.getElementById("name").value;
}
function mostrar(){
document.getElementById("demo").innerHTML = x;
}
<input type="text" id="name">
<button onclick="crear()">Crear</button>
<button onclick="mostrar()">Mostrar</button>
<h1 id="demo"></h1>