Menu
Coddy logo textTech

String Fundamentals

Part of the Logic & Flow section of Coddy's JavaScript journey — lesson 1 of 65.

In JavaScript, strings are immutable. This means that once a string is created, its value cannot be changed. Any operation that appears to modify a string actually creates a new string.

Here's an example:

let str = "Hello";
str[0] = "h"; // This doesn't work
console.log(str); // Still outputs "Hello"

When you perform operations on strings, you're creating new strings:

let str = "Hello";
let newStr = str + " World";
console.log(str);     // "Hello"
console.log(newStr);  // "Hello World"

While strings and arrays are different data types, they share many similar methods. For example, both support methods like:

  • includes()
  • indexOf()
  • length
  • slice()

However, remember that unlike arrays, strings are immutable, so methods that modify arrays (like push() or pop()) don't exist for strings.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

Cheat sheet

Strings in JavaScript are immutable - once created, their value cannot be changed. Any operation creates a new string:

let str = "Hello";
str[0] = "h"; // This doesn't work
console.log(str); // Still outputs "Hello"
let str = "Hello";
let newStr = str + " World";
console.log(str);     // "Hello"
console.log(newStr);  // "Hello World"

Strings and arrays share similar methods like includes(), indexOf(), length, and slice(), but strings don't have array modification methods like push() or pop().

Try it yourself

This lesson doesn't include a code challenge.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Logic & Flow