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

I was trying to do something like this in consolevar a = {title : '123'}a && a.title

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'

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745459742a4628651.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信