Below is the code,
<p id="sayHello"></p>
<script type="text/javascript">
var yourName = window['prompt']("What is your name?");
if (yourName != null) {
window['document']['getElementById']("sayHello").innerHTML = "Hello " + yourName;
} else {
window['alert']("Please enter your name next time");
}
</script>
for which, else block need to get executed based on the input given in prompt.
What should be the input in prompt box to test null value of primitive type Null?
== null/!= nullis totally fine. What exactly is your question? Doesn't that code work?Nullprimitive valuenullpromptreturns thenullvalue when being cancelled, and comparing withnulltotally tests for that condition.