An extremely simple example of using prompt
goes as follows:
<!DOCTYPE html>
<html lang="en">
<head></head>
<body>
<script>
var name = prompt("Please enter your name");
if (name != null) {
console.log('problem!!!');
}
</script>
</body>
</html>
With this code, whether you click OK, click Cancel, or close the prompt box by clicking the cross -- in all cases you see problem!!!
in Chrome dev tools. But if you change name
to something else...
<!DOCTYPE html>
<html lang="en">
<head></head>
<body>
<script>
var randomName = prompt("Please enter your name");
if (randomName != null) {
console.log('problem!!!');
}
</script>
</body>
</html>
...then problem!!!
ONLY shows up if you click OK. How is that possible? Why does changing variable name change behavior of prompt
function?