Undefined variable is used to check if the variable has assigned any value or not? In this example of undefined, We are checking if the variable x is undefined and yes this is undefined. you can check it by clicking on the button.

<!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 x; if (x === undefined) { txt = "x is undefined"; } else { txt = "x is defined"; } document.getElementById("sample").innerHTML = txt; } </script> </body> </html>