Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Client Scripting
Expertise: Beginner
Nov 2, 1999



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Handling Single and Double Quotes


I am trying to put lines of text into an array:

messageArray = new Array();
messageArray[0] = 'Information deduced from the document's content.'

I'm running into problems with the single quotes (') because it thinks that the text is over and that there is an extra '. What can I do about this?


Luckily there is a simple solution to the problem you've run into. You can either use double quotes (") or single quotes (') to delimit your JavaScript strings. So if your string is likely to include one kind of quote within it, just use the other kind to actually tell the browser where the string starts and ends. For example:

messageArray[0] = "Information deduced from the document's content.";

You can also escape the quotes within your strings by putting a backslash before them. Like this:

\' Single quotation mark
\" Double quotation mark

DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date