undefined-3

 

undefined-3

 
 
 
<!DOCTYPE html> <html> <head> <title>Welcome to LearnKode - A code learning platform</title> </head> <body> <p>Click the button to check whether the variables have been assigned a value or not.</p> <button onclick="checkUndefined()">Click it</button> <p id="sample"></p> <script> function checkUndefined() { var x1 = "myFunction"; var x2; if (x1 === undefined) { txt1 = "x1 is undefined"; } else { txt1 = "x1 is defined"; } if (x2 === undefined) { txt2 = "x2 is undefined"; } else { txt2 = "x2 is defined"; } txt = txt1 + "<br>" + txt2; document.getElementById("sample").innerHTML = txt; } </script> </body> </html>
Output