Eloquent JavaScript - Values Variables Control Flow

the || operator

by Denise Nepraunig

HTML

<div id="output"></div>

JavaScript

var input = prompt("What is your name?", "");
document.getElementById("output").innerHTML = "Well, hello " + (input || "unknown") + "!";

// the || operator returns the first value, if the value is 'true'/has a value