Back to JavaScript Notes
Topic #295

JavaScript Strings

You will be able to create JavaScript strings as text values using quotes, backticks, and conversion, and explain when each form is appropriate.

What it is

A JavaScript string is a primitive text value: an ordered sequence of characters such as letters, digits, spaces, and punctuation. Strings are immutable, meaning once a string exists, its characters cannot be changed in place. Operations like toUpperCase() return a new string instead of modifying the original.

Related terms include string literal, template literal, interpolation, escape sequence, and string conversion. A literal is text written directly in code. A template literal is a special string form that can embed expressions.

Why it matters

  • Strings store user names, messages, URLs, file paths, and form input.
  • Template literals make dynamic text easier to read than many + concatenations.
  • String conversion lets numbers, booleans, and other values become text for display.
  • Understanding immutability prevents bugs when editing text.
  • Quotes and escaping are needed when text contains punctuation or code.

Syntax or steps

The smallest useful pattern is a string literal assigned to a variable:

const s = "Hello";

JavaScript accepts three common literal forms:

const single = 'Hello';
const double = "Hello";
const template = `Hello`;

Use String(value) to convert values such as numbers and booleans into a string:

const year = String(2026);

Inside a template literal, ${expression} inserts the result of an expression:

const name = "Ada";
const greeting = `Hello, ${name}!`;

Example

const city = "Paris";
const population = 2100000;

const label = `City: ${city}`;
const combined = "Population: " + population;
const converted = String(true);

console.log(label);
console.log(combined);
console.log(converted.length);

Part by part:

  • const city = "Paris"; creates a double-quoted string.
  • `City: ${city}` creates a template literal and inserts the value of city.
  • "Population: " + population concatenates a string with a number, producing a new string.
  • String(true) converts the boolean true into the string "true".
  • converted.length reads the number of UTF-16 code units in the string.

Common mistakes

  • Unescaped quotes. 'It's done' is invalid because the second quote ends the string. Fix it with "It's done" or 'It\'s done'.
  • Using normal quotes for interpolation. 'Hello, ${name}' prints the literal text ${name}. Fix it by using backticks.
  • Trying to mutate a string. s[0] = "h" does not change s. Fix it by creating a new string, such as s.replace("H", "h").
  • Confusing concatenation with addition. "5" + 1 produces "51", not 6. Fix it by converting first, such as Number("5") + 1.

When to use it

Choose the form based on whether you need simple text, dynamic text, or conversion.

FormUse whenExample
Single or double quotesYou need a simple literal string.const s = "Hello";
Template literalYou need interpolation or multiline text.const s = `Hello, ${name}!`;
String(value)You need to convert a non-string value to text.const s = String(42);

Prefer template literals over long concatenation chains when readability matters. Avoid new String("text") unless you specifically need an object wrapper; it is rarely useful in normal code.

Practice

  1. Guided exercise: Create a variable named language with the value "JavaScript". Then create message using a template literal that says I am learning JavaScript.. Expected output: I am learning JavaScript.
  2. Challenge: Convert the number 100 to a string and concatenate it with " points". Hint: use String(100) + " points" or `${100} points`.

Quick check

Question: Which string form allows ${expression} interpolation?

Answer: A template literal written with backticks.

Summary

JavaScript strings are immutable text values created with quotes, backticks, or conversion functions. Use simple literals for fixed text, template literals for dynamic text, and String() when converting other values into text.

Want to go beyond the notes?

Join Coding Now Tech Institute's JavaScript course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

JavaScript Strings – FAQs

Quick answers about learning JavaScript Strings in JavaScript.

This free note from Coding Now Tech Institute explains JavaScript Strings in JavaScript — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every JavaScript topic on Coding Now Tech Institute, including JavaScript Strings, is 100% free with no signup required.
With focused practice, most students grasp JavaScript Strings in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now