Javascript examples for Data Type:undefined
The undefined property indicates that a variable has not been assigned a value.
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {//from w w w .j a v a 2 s. co m var t1 = "myVar"; var t2; if (t1 === undefined) { txt1 = "t1 is undefined"; } else { txt1 = "t1 is defined"; } if (t2 === undefined) { txt2 = "t2 is undefined"; } else { txt2 = "t2 is defined"; } txt = txt1 + "<br>" + txt2; document.getElementById("demo").innerHTML = txt; } </script> </body> </html>