wrt
wrt

Reputation: 21

javascript error "SyntaxError: Unexpected token &&"

I was trying to do something like this in console

var a = {title : '123'}
a && a.title //" 123"

but when I do this I have an error

{title : '123'} && '123'
**ERROR SyntaxError: Unexpected token &&**

I don't understand what conversions V8 did

Upvotes: 2

Views: 5089

Answers (1)

Denys Séguret
Denys Séguret

Reputation: 382150

The first part is parsed as a block with a label. So what follows is the start of a statement. && is a binary operator (meaning taking two operands), it can't start a statement.

Make the first part an expression by using parenthesis :

({title : '123'}) && '123'

Upvotes: 5

Related Questions