JavaScript Strings


A JavaScript string is zero or more characters written inside quotes.


Example

var x = "John Doe";


You can use single or double quotes:


Example

var carName1 = "Volvo XC60";  // Double quotes

var carName2 = 'Volvo XC60';  // Single quotes


You can use quotes inside a string, as long as they don't match the quotes surrounding the string:


Example

var answer1 = "It's alright";

var answer2 = "He is called 'Johnny'";

var answer3 = 'He is called "Johnny"';


String Length

To find the length of a string, use the built-in length property:


Example

var txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

var sln = txt.length;


Jay Kakadiya

Jay Kakadiya Creator

I am a computer field, & i am Web developer.

Suggested Creators

Jay Kakadiya