This works:
alert('foo\
bar'
)
But this is causing syntax error:
t='test';
alert('<tr><td><b>' + t + '</b></td>\
<td></td><td>')
error is:
SyntaxError: unterminated string literal
They two should be the same thing, why the first one works, while the second fails?
asked Sep 26, 2011 at 11:20
-
2Maybe you have extra spaces after the back-slash?Luchian Grigore– Luchian Grigore2011年09月26日 11:25:44 +00:00Commented Sep 26, 2011 at 11:25
1 Answer 1
You have a trailing space after your backslash in the second example.
answered Sep 26, 2011 at 11:26
Sign up to request clarification or add additional context in comments.
2 Comments
Daniel Brockman
By the way, it may be worth pointing out that trailing whitespace in any piece of code is pretty much universally frowned upon in the programming community. Many editors will highlight it as an error regardless of the context. (The only exception to this is lines consisting entirely of whitespace.)
Daniel Brockman
@J.J. No, I don’t see any trailing spaces in the first example.
lang-js