How to Use Text in JavaScript Code

By Chris Minnick, Eva Holland

Unlike in strings in JavaScript, the contents and spelling of text outside of quotes matters a lot. When text isn’t surrounded by quotes (single or double) in JavaScript, it’s considered part of the code of the JavaScript program.

JavaScript code is very picky about spelling and capitalization. In JavaScript code, the following words are completely different:

FOR
for
For

Only the one in the middle means anything special to JavaScript. If you try to use the other two in the message printer program, you’ll get an error, as shown here.

Capitalizing a JavaScript keyword wrong produces errors.

Capitalizing a JavaScript keyword wrong produces errors.

JavaScript is also very picky about spelling. Many times, when you’re coding and something just isn’t working right, the problem turns out to be that you accidentally left out a letter or mixed up the order of two letters.

Just as typos in writing often go unnoticed, these types of errors can be very difficult to track down, so get into the habit early on of typing slowly and carefully, and you’ll save yourself a lot of time in the long run!