"I'm a String in JavaScript!" 'So am I!'
A string in JavaScript is an immutable object that contains none, one or many characters.
The type of a string is "string".
typeof "some string"; // "string"
Quoting
A string can be defined using single or double quotes. You can nest single quotes inside of double quotes, and the other way round. To mix double quotes with double quotes, the nested ones have to be escaped with a backslash.
"You make 'me' sad." 'Holy "cranking" moses!' "<a href="home">Home</a>"
Built-in Methods
A string in JavaScript has some built-in methods to manipulate the string, though the result is always a new string - or something else, eg. split returns an array.
"hello".charAt(0) // "h"
"hello".toUpperCase() // "HELLO"
"Hello".toLowerCase() // "hello"
"hello".replace(/e|o/g, "x") // "hxllx"
"1,2,3".split(",") // ["1", "2", "3"]
Boolean Default
An empty string defaults to false:
!"" // true !"hello" // false !"true" // false !new Boolean(false) // false
Was this information helpful?

