Because this[x] is undefined , which is false, and therefore null .
Operator || returns the first "true" value that it finds, and stops its evaluation at that point.
If no "true" value is found, it returns the result of evaluating the last operand.
In total, there are 6 false values. They are...
Everything else is considered true.
So your expression will be evaluated as ...
// v--falsey v--truthy! return it! ((((this[x] || null) || 'aïe') || 12) || undefined); // ^--falsey ^--------^---these are not evaluated at all
Or you can look at it like this:
( ( ( (this[x] || null)
user1106925
source share