Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why "{} || {}" throws syntax error?

Tags:

javascript

This works:

var a = {} || {};

While this does not:

{} || {};
Uncaught SyntaxError: Unexpected token ||
    at Object.InjectedScript._evaluateOn (<anonymous>:905:140)
    at Object.InjectedScript._evaluateAndWrap (<anonymous>:838:34)
    at Object.InjectedScript.evaluate (<anonymous>:694:21)

Why is that? Tested on ff and chrome.

like image 857
Maciej Dziardziel Avatar asked Dec 14 '22 12:12

Maciej Dziardziel


1 Answers

Javascript considers braces to be a code block. Try this:

({} || {});
like image 189
Kędrzu Avatar answered Dec 31 '22 06:12

Kędrzu