A string can be any text inside quotes. You can use single or double quotes:
You can use quotes inside a string, as long as they don't match the quotes surrounding the string:
The length of a string is found in the built in property length:
The string will be chopped to "We are the so-called ".
The solution to avoid this problem, is to use the \ escape character.
The backslash escape character turns special characters into string characters:
The escape character (\) can also be used to insert other special characters in a string.
This is the list of special characters that can be added to a text string with the backslash sign:
Breaking Long Code Lines
For best readability, programmers often like to avoid code lines longer than 80 characters.
You can also break up a code line within a text string with a single backslash:
The safest (but a little slower) way to break a long string is to use string addition:
You cannot break up a code line with a backslash:
Strings Can be Objects
But strings can also be defined as objects with the keyword new: var firstName = new String("John")
Don't create strings as objects. It slows down execution speed. The new keyword complicates the code. This can produce some unexpected results:
When using the == equality operator, equal strings looks equal:
When using the === equality operator, equal strings are not equal, because the === operator expects equality in both type and value.
Or even worse. Objects cannot be compared: