<html>
<body>
<p>Click the button to check whether the variable y is defined or undefined.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
if (typeof y === "undefined") {
txt = "y is undefined";
} else {
txt = "y is defined";
}
document.getElementById("demo").innerHTML = txt;
}
</script>
</body>
<!-- Mirrored from www.w3schools.com/jsref/tryit.asp?filename=tryjsref_undefined2 by HTTrack Website Copier/3.x [XR&CO'2014], Mon, 27 Jan 2020 03:01:29 GMT -->
</html>