Interesting JavaScript string capability

Reading through ECMA-262 and taking a look at Rhino‘s source code, I came across something interesting. Apparently, it is possible to have a JavaScript string begin on one line of code and end on another line of code. For example:

var s /*:String*/ = "Test \
multi \
line.";
alert(s);

This is perfectly valid; the interpreter just ignores the slash and the line break. The output from this code snippet is “Test multi line.” Just goes to show, you can write books on a topic and still not know everything about it.

Master JavaScript Promises

Free E-book - Understanding JavaScript Promises

What You'll Learn

  • Promise fundamentals and concepts
  • Real-world promise implementations
  • Best practices and patterns
  • Error handling techniques

Demystify JavaScript promises with practical examples and expert insights.

Download Your Free Copy

The community edition arrives in your inbox within minutes.