JavaScript String Object JavaScript String Object

This tutorial introduces the JavaScript String object. Strings are the native JavaScript data type used to hold text values; any JavaScript object can easily be converted to a string using the universal toString() method.

Strings can even contain numbers: but numbers enclosed in quotes (single or double) cannot be used for mathematical operations before first being converted. The same applies for a quoted boolean of true or false.

What is a String?

A JavaScript string is a variable container designed for text, or any values directly or indirectly converted to String data type (text).

The single most common trait of strings is to be enclosed in single- or double-quotes. Both variables declared below are strings; they in fact are identical. (Single- and double-quotes are interchangeable in JavaScript.)

var carter1 = "I learn JavaScript";
var carter2 = 'I learn JavaScript';

Both variables are easily recognized as strings, thanks to their enclosure in quotes. Our next tutorial explains how to declare strings in JavaScript.

JavaScript String Properties

Properties are "attributes" attached to string-type values in JavaScript. In the case of strings, we have three properties at our disposal:

JavaScript String Methods

Our tutorials will cover the most common JavaScript string methods. Methods are special functions available to different types of objects; like other objects, JavaScript strings have numerous manipulation and conversion methods.