I do not understand why the alert is not displayed
<!DOCTYPE html>
<html lang="en">
<head>
<title>Prueba</title>
</head>
<body>
<br>
<input type = "text" id = "texto" ></imput><br>
<input type = "button" value = "boton" onclick = "validar()"></imput>
</body>
</html>
<script>
function validar(){
var str = document.getElementById("texto").value;
}
alert(str);
</script>