This reminds me of Gary Bernhardt's "Wat" talk, but why is {} || 3
a syntax error?
> 3 || {}
3
> {} || 3
VM2330:1 Uncaught SyntaxError: Unexpected token '||'
> {} + 3
3
> a = {}
{}
> a || 3
{}
This reminds me of Gary Bernhardt's "Wat" talk, but why is {} || 3
a syntax error?
> 3 || {}
3
> {} || 3
VM2330:1 Uncaught SyntaxError: Unexpected token '||'
> {} + 3
3
> a = {}
{}
> a || 3
{}
You need to make an expression with patentheses.
({} || 3)
Oterwise you take a block statement and this is not an expression for use with an operator.