N Newline (Escape sequence) (Web site translator) Cross-references: ECMA 262
N Newline (Escape sequence) Cross-references: ECMA 262 edition 2 section 11.2.2 ECMA 262 edition 2 section 11.2.4 ECMA 262 edition 2 section 15 ECMA 262 edition 3 section 11.2.2 Wrox Instant JavaScript page 15 Wrox Instant JavaScript page 21 Newline (Escape sequence) A means of introducing line breaks into string content texts. Availability: ECMAScript edition 2 The newline escape sequence n can be placed in string literals if you want to break the output text over more than one line. Warnings: . Do not use a line terminator even with a backslash to escape it. In other words, don’t think that placing a backslash as the last character of a line will hide the line terminator. While that may work in other languages, it won’t work in JavaScript. See also: Escape sequence (), Line terminator Cross-references: ECMA 262 edition 2 section 7.2 ECMA 262 edition 2 section 7.7.4 ECMA 262 edition 3 section 7.3 Newlines are not
tags (Pitfall) A newline in a script does not display a line break in HTML output. Because HTML is fairly freely formatted, you have to explicitly tell it when a line break is to appear. You can do this a variety of block-level tags. Its most likely done with a
or
tag. When you use the document.write() method, you need to explicitly include the necessary
or
tags otherwise the HTML output that gets displayed will all run onto a single line. Placing a nnewline escape into the output may make the HTML source look nice but it won’t affect the displayed output. 1523