When I run this code firstly shows me 1 and then undefined. But I still couldn't understand it.
alert(alert(1) && alert(2));
Here is some explanation :
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.