Advertisement

Google Ad Slot: content-top

JS Strings


A string in JavaScript is a sequence of characters used to represent textual data. Strings are immutable, meaning their content cannot be changed once created.

Creating Strings

You can create a string in three ways:

Using Single Quotes ('):

Example
let str = 'Hello, World!';

Using Double Quotes ("):

Example
let str = "Hello, World!";

Using Template Literals (Backticks ` `):

  • Supports multi-line strings
  • Allows string interpolation (${expression})
Example
let name = 'John';
let greeting = `Hello, ${name}!`;
console.log(greeting); // Output: Hello, John!
Try it yourself