---
title: "JavaScript: Strings"
date: 2013-02-02
description: "Strings are non-numbers assigned to variables. You surround strings in quotes, like this: {% highlight javascript %}var endMessage ="
canonical_url: https://idratherbewriting.com/strings-javascript/
---
# JavaScript: Strings
Strings are non-numbers assigned to variables. You surround strings in quotes, like this:

If you have a quote inside a quote, you can add a back slash to tell JavaScript to ignore the quotation mark (this is called "escaping"). Otherwise, the quotation mark inside the string would end your string. In the following example, the quotations around `relax` are escaped.

Single quotes inside double quotes are allowed without the need to escape them. If you have contractions or possessives, which use single quote marks, make sure you surround the string with double quotes.

## Strings as Arrays

Variables with strings can be treated as arrays. If you add `.length` to the variable, JavaScript returns the number of characters in the string.