Home

How to Use Text in JavaScript Code

|
Updated:  
2016-03-26 07:26:23
|
JavaScript Essentials For Dummies
Explore Book
Buy On Amazon

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!

About This Article

This article is from the book: 

About the book author:

Chris Minnick is an accomplished author, teacher, and programmer. Minnick authored or co-authored over 20 books, including titles in the For Dummies series. He has developed video courses for top online training platforms and he teaches programming and machine learning to professional developers at some of the largest global companies.

Eva Holland is an experienced web developer, tech trainer, and coauthor of Coding with JavaScript For Dummies. She is a co-founder of WatzThis?, a company focused on training and course development.