简体   繁体   中英

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

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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM