admin管理员组文章数量:1402803
I try to evaluate this expression in Node.js v8.9.4:
`${ xxx 123 }`
It throws the error
Missing } in template expression
I understand that the expression above should cause
an error because the contents inside ${}
are not
valid JavaScript. But why does the error-message
claim a }
is missing? I can clearly see an opening
{
and a closing }
. Why is it saying a }
is missing?
I try to evaluate this expression in Node.js v8.9.4:
`${ xxx 123 }`
It throws the error
Missing } in template expression
I understand that the expression above should cause
an error because the contents inside ${}
are not
valid JavaScript. But why does the error-message
claim a }
is missing? I can clearly see an opening
{
and a closing }
. Why is it saying a }
is missing?
-
3
xxx 123
is not a valid expression – Jorg Commented Mar 12, 2018 at 3:03 -
1
Why is it saying a '}' is missing?
because, when trying to figure out what you're trying to do, I guess that's the parser error that es up – Jaromanda X Commented Mar 12, 2018 at 3:03 -
1
I think because it expects
${ xxx }
? – rafaelgomesxyz Commented Mar 12, 2018 at 3:04 - Because it is expecting the the interpolation to be closed between expressions; xxx and 123 – treyhakanson Commented Mar 12, 2018 at 3:07
-
1
Yeah, Jorg is correct, I think the problem is that
xxx 123
is not a valid expression, so however it is trying to parse it this is the best error it can e up with for whatever it things you are trying to do. Are you perhaps intending it to be`${xxx} 123`
wherexxx
is some variable you have saved? – Alexander Nied Commented Mar 12, 2018 at 3:07
1 Answer
Reset to default 6You say there is a closing brace, but the JS parser doesn't get that far because it breaks between xxx
and 123
.
The syntax expects an opening brace, an expression, then a closing brace. What it gets is an opening brace, an expression then another expression. So at that point the error is precisely what is says. And in fact, if you add the brace as it suggests, it will work ${ xxx } 123 }
. It may be not what you intended, but you can't say it is ill-formed.
本文标签:
版权声明:本文标题:javascript - Why does the syntax error message say "Missing } in template expression" if there is a closing br 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744360331a2602511.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论