Welcome to Bucaro TecHelp!

Bucaro TecHelp
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

About Bucaro TecHelp About BTH User Agreement User Agreement Privacy Policy Privacy Site Map Site Map Contact Bucaro TecHelp Contact RSS News Feeds News Feeds

Victims of Sandy Hook

Stop the Slaughter of Innocents. Congress is bought and paid for by gun lunatics and gun promotion groups. If you want to live in a safe America, help buy Congress back for America. Send a donation to Mayors Against Illegal Guns, 909 Third Avenue, 15th Floor New York, NY 10022

Define Lines in a String

You know that to define a String in Java Script requires that you enclose the data within quotes. For example, the statement below displays a string (the first line in Abraham Lincoln's in the Gettysburgh address) in a message box.

alert("Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.");

(code required to be on one line.)

Message box too wide

As you can see above, this creates an unappealing too wide message box. We can improve the aspect ratio of the message box by placing newline \n character escape sequences within the string to explicitly define where the string should break to create a new line, as shown below.

alert("Four score and seven years ago our fathers\n brought forth on this continent, a new nation,\n conceived in Liberty, and dedicated to the\n proposition that all men are created equal.");

(code required to be on one line.)

More appealing message box

This creates the more appealing message box shown above.

If you want to format your code so that it has the same line structure as that displayed in the message box, enclose each line in quotes and use the string concatenation operator to rejoin the lines, as shown below.

alert("Four score and seven years ago our fathers\n" + "brought forth on this continent, a new nation,\n" + "conceived in Liberty, and dedicated to the\n" + "proposition that all men are created equal.");

This makes your code more neat and more understandable.

RSS Feed RSS Feed



Follow Stephen Bucaro Follow @Stephen Bucaro


Web Design Sections

Fire HD
[Site User Agreement] [Privacy Policy] [Site map] [Search This Site] [Contact Form]
Copyright©2001-2016 Bucaro TecHelp 13771 N Fountain Hills Blvd Suite 114-248 Fountain Hills, AZ 85268