JavaScript Data Type: Strings

By: Dusty Arlia
Published on August 9, 2012
Last Updated on Saturday, July 11, 2015 at 6:51 PM
Total Updates: 7

A string is a series of letters and other symbols. Strings are variables that can hold the value of a name, sentence, title, or even HTML code. Place your string in between quotation marks. For example, you can use double quotes ("Hello world") or single quotes ('Hello world'). It doesn't matter which type of quote you use, just don't mix them. For example don't do this: "Hello World'. Learn more about using quotes properly in JavaScript strings.

A string's opening quotation mark signals to the JavaScript interpreter that what follows is a string. The interpreter interprets each character of the string literally (as opposed to having a special meaning in the JavaScript language). When the JavaScript interpreter encounters the closing quotation mark, it knows it has reached the end of the string. Here's an example of a string in action:

alert("Hello World!");