Why does Javascript's OR return a value other than true/false?
Posted
by Fletcher Moore
on Stack Overflow
See other posts from Stack Overflow
or by Fletcher Moore
Published on 2010-06-03T13:35:56Z
Indexed on
2010/06/03
13:44 UTC
Read the original article
Hit count: 267
JavaScript
|syntax
I saw this construction in order to get the browser viewport width:
function () { return window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; }
I understand the browser quirks involved. What I don't understand is why ||
returns the value. So I tried this alert(undefined || 0 || 3);
and sure enough, it alerts 3
. I find this bizarre, because I expect true
or false
. Could anyone explain what's going on?
© Stack Overflow or respective owner