5

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
1
  • 2
    Maybe you have extra spaces after the back-slash? Commented Sep 26, 2011 at 11:25

1 Answer 1

2

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

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.)
@J.J. No, I don’t see any trailing spaces in the first example.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.