Rolf B: Abbruch-Behandlung für Javascript prompt fehlt

Beitrag lesen

Hallo Linuchs und Martin,

ich wage zu widersprechen.

Abbrechen von prompt() ergibt bei mir nicht FALSE, sondern NULL. Und das schreibt auch die HTML Spec (8.8.1 Simple Dialogs).

If the user cancels the prompt, then returns null instead.

Bitte prüft euren Versuchsaufbau. Kam da wirklich false?

let ergebnis = prompt("What is six multiplied by nine", "42");
console.log("Typ von Ergebnis ist " + (typeof ergebnis));
if (ergebnis === null) 
   console.log("Ergebnis ist null");
else if (ergebnis === false) 
   console.log("Ergebnis ist false");
else 
   console.log("Ergebnis ist " + ergebnis);

Der ausgegebene Typ sollte object sein (weil das der Typ von null ist), und nicht boolean.

Rolf

--
sumpsi - posui - obstruxi