JavaScript String

Beginner
8 min read
Updated: Nov 2026
3 examples
UTF-16 text

Definition and Usage

In JavaScript, a String is a text value. It can hold letters, digits, spaces, and symbols. You write a string with single quotes, double quotes, or backticks: 'Code', "ToFun", or `Hello, ${name}`.

Strings are primitives and they are immutable. Calling toUpperCase() or slice() returns a new string. The value you started with does not change. Join text with + or a template literal. "JS" + 1 becomes the string "JS1", because + concatenates when either side is text.

This page teaches what a String is. The String Methods index and String Properties index list every method and property guide (slice(), includes(), length, and more).

Prefer primitives.

Use a quoted literal or String(value)—not new String(value). Object wrappers make typeof return "object".

JavaScript Syntax

Common ways to create and inspect strings:

JavaScript
const title = "JavaScript";     // double quotes
const lang = 'JS';               // single quotes
const name = "Ada";
const greet = `Hello, ${name}`;  // template literal
const typed = typeof title;      // "string"
const count = title.length;      // 10
const made = String(42);         // "42"

Core Ideas

Ideas every JavaScript String tutorial builds on:

IdeaExampleRemember
Quotes"hi" / 'hi'Same string either way
Template`Hi, ${name}`Inserts values and line breaks
Join"JS" + 1Result is "JS1"
Immutables.toUpperCase()Returns a new string
length"Hi".lengthUTF-16 code units, not graphemes
ConvertString(true)Always a string primitive

JavaScript Examples

Three short programs that show how String works in a JS tutorial.

Example 1 — Quotes and a template literal

Build text with quotes, +, and ${}.

JavaScript
const single = 'Code';
const double = "ToFun";
const name = "Ada";
const greet = `Hello, ${name}`;

console.log(single + double);
console.log(greet);
console.log(typeof greet);

How It Works

  1. + joins two strings with no extra space.
  2. ${name} inserts the value of name inside the backticks.
  3. typeof of a quoted or template string is "string".

Example 2 — Methods return a new string

toUpperCase() does not rewrite the original variable.

JavaScript
let word = "java";
const upper = word.toUpperCase();

console.log(word);
console.log(upper);

word[0] = "J";
console.log(word);
Case methods

How It Works

  1. toUpperCase() returns "JAVA" and leaves word as "java".
  2. Index assignment does not edit a string character in place.
  3. Keep the result in a new variable when you need the changed text.

Example 3 — Concatenation and length

+ with a number makes text. length counts code units.

JavaScript
const label = "JS";

console.log(label + 1);
console.log("Hi".length);
console.log("😀".length);
console.log(String(true));
length tutorial

How It Works

  1. "JS" + 1 concatenates, so the result is the string "JS1".
  2. "Hi".length is 2, one code unit per letter.
  3. "😀".length is also 2, because that emoji is a surrogate pair. String(true) is "true".

Next: Methods & Properties Indexes

After you know what a String is, open the indexes for full tutorials on every essential String API in this JavaScript series.

Start withWhy
lengthCount characters and check empty text
slice()Copy part of a string
includes()Ask whether text contains a substring
trim()Drop spaces from both ends

Full lists: String Methods index and String Properties index.

Frequently Asked Questions

A String is text: letters, digits, spaces, and symbols stored as a sequence of UTF-16 code units. You write it with quotes or a template literal, for example "hello", 'hello', or `hello`.
No. Methods such as toUpperCase() and slice() return a new string. The original value stays the same. Assigning to an index, such as word[0] = "J", does not change the string.
Single and double quotes are plain text. A template literal uses backticks and can insert values with ${name}. It can also span more than one line.
length counts UTF-16 code units, not visible characters. Many emoji use a surrogate pair, so "😀".length is 2 while "Hi".length is 2 for two letters.
Practice the examples here, then open the String Methods index for slice(), includes(), trim(), and replace(), and the String Properties index for length and constructor.

Browse every String method

Open the index for slice(), includes(), trim(), replace(), and the rest.

String Methods index →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful