We want to make this open-source project available for people all around the world.

Help to translate the content of this tutorial to your language!

BuyEPUB/PDF
Share
back to the lesson

What is the result of AND'ed alerts?

importance: 3

What will this code show?

alert( alert(1) && alert(2) );

The answer: 1, and then undefined.

alert( alert(1) && alert(2) );

The call to alert returns undefined (it just shows a message, so there’s no meaningful return).

Because of that, && evaluates the left operand (outputs 1), and immediately stops, because undefined is a falsy value. And && looks for a falsy value and returns it, so it’s done.

AltStyle によって変換されたページ (->オリジナル) /