undefined-2

 
Example of undefined: In this example, it will return variable is undefined because it will check the datatype as well.
 
 
 
<!DOCTYPE html> <html> <head> <title>Welcome to LearnKode - A code learning platform</title> </head> <body> <p>Click the button to test if a variable is undefined.</p> <button onclick="checkUndefined()">Click it</button> <p id="sample"></p> <script> function checkUndefined() { var y; if (typeof y === undefined) { txt = "y is undefined"; } else { txt = "y is defined"; } document.getElementById("sample").innerHTML = txt; } </script> </body> </html>
Output