I have been writing some code pertaining to random number generating, and I would add the user's name to the sentence that was produced by the script.
The user inputs their answer with a prompt. I wanted to know how to check for null
, so I tested this with the answer given by multiple sources on Stack Overflow. However, it does not work for null
. Curiously, it does work when null
is inputted as a string: "null"
. I have read over and over again that null
is not a string, so why would that work?
My code for the test is below:
<!DOCTYPE html>
<html>
<head>
<title>Check</title>
<script>
var name = prompt("What's up?");
function check() {
if (name === null) {
document.write("null");
}
}
</script>
</head>
<body id="body" onload="check()">
</body>
</html>