最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript error "SyntaxError: Unexpected token &&" - Stack Overflow

programmeradmin0浏览0评论

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

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

Share Improve this question asked Mar 16, 2014 at 19:48 wrtwrt 211 silver badge4 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

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'
发布评论

评论列表(0)

  1. 暂无评论