Coding Manifestation Logo
Lesson 14

Strings Basics

Strings are used to represent text. A string is a sequence of characters wrapped in single, double, or backticks.

“”H0e1l2l3o4
  • What is a String?
  • Creating Strings
  • Accessing Characters
  • String Length
  • Common Operations
  • String Methods
  • Template Literals
let message = "Hello, World!"
Index0123456789101112
CharHello,World!

Length: 13

A
Sequence of Characters

A string is a collection of characters.

Can Use Quotes

Use single ( ' ), double ( " ) or backticks ( ` ).

#
Zero-based Indexing

First character is at index 0.

Has a Length

Use .length to find the number of characters.

JavaScript
Output
Your output will appear here...
OperationExampleResultDescription
Concatenation'Hello' + ' ' + 'DSA'Hello DSACombines two or more strings.
toUpperCase()'hello'.toUpperCase()HELLOConverts string to uppercase.
toLowerCase()'HELLO'.toLowerCase()helloConverts string to lowercase.
includes()'Master DSA'.includes('DSA')trueChecks if substring exists.
slice()'Master DSA'.slice(7, 10)DSAExtracts part of a string.
replace()'I love JS'.replace('JS', 'DSA')I love DSAReplaces substring.
  • str.length
    // Length of string
  • str[index]
    // Character at index
  • str.charAt(index)
    // Character at index
  • str.slice(start, end)
    // Substring
  • str.toUpperCase()
    // Uppercase string
  • str.toLowerCase()
    // Lowercase string
  • str.includes(sub)
    // Check substring
let str = "Hello"str.toUpperCase();Originalunchanged"HELLO" (new string)

Strings are immutable in JavaScript. Methods like toUpperCase() return a new string instead of changing the original.

PrevNext