Is there a character in JS to break up a line of code to read it as continuous despite being on a new line?
Something like....
1. alert ( "Please Select file
2. \ to delete" ); <-- ?
Thanks
Is there a character in JS to break up a line of code to read it as continuous despite being on a new line?
Something like....
1. alert ( "Please Select file
2. \ to delete" ); <-- ?
Thanks
In your example, you can break the string into two pieces:
alert ( "Please Select file"
+ " to delete");
Or, when it's a string, as in your case, you can use a backslash as @Gumbo suggested:
alert ( "Please Select file\
to delete");
When working with other code (not in quotes), line breaks are ignored, and perfectly acceptable. For example:
if(SuperLongConditionWhyIsThisSoLong
&& SuperLongConditionOnAnotherLine
&& SuperLongConditionOnThirdLineSheesh)
{
// launch_missiles();
}
Put the backslash at the end of the line:
alert("Please Select file\
to delete");
Edit I have to note that this is not part of ECMAScript strings as line terminating characters are not allowed at all:
A 'LineTerminator' character cannot appear in a string literal, even if preceded by a backslash
\
. The correct way to cause a line terminator character to be part of the string value of a string literal is to use an escape sequence such as\n
or\u000A
.
So using string concatenation is the better choice.
You can just use
1: alert("Please select file" +
2: " to delete");
That should work
Break up the string into two pieces
alert ("Please Select file" +
"to delete");