<!DOCTYPE html>
<html>
<body>
<p>Click the button to test if a variable is undefined.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var x;
if (x === undefined) {
txt = "x is undefined";
} else {
txt = "x is defined";
}
document.getElementById("demo").innerHTML = txt;
}
</script>
</body>
</html>