← JavaScript

String Indexing and Length

The number of characters in a string, accessed as a property without parentheses.

Understanding String Indexing and Length in JavaScript

What it does: Since indexing starts at 0, index 1 is the second character. length is accessed directly as a property, not called as a method. Strings are indexed starting at 0, just like arrays. length counts every character in the string, including spaces. Square brackets [], not round brackets, access a character by index. JavaScript is case-sensitive, so it must be lowercase 'length'. Every [ used for indexing needs a matching ]. Index 0 always refers to the first character in a string.

Common mistakes: Use square brackets [], not round brackets, to access a character. Use square brackets [], not round brackets, to access a character.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 21–30) and word search (Modules 1–29) and word search (Modules 21–52).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Does word[0] access the first character of a string?
YesNo
Matches
console.log(word(0));
↓
Wrong - use square brackets, not round brackets
Applying
Meanings
Term
length
Meaning
The number of characters in a string, accessed as a property without parentheses.
Practice
let word = "hello";
Testing
Gaps
console.log(word0]);
Check Answer
Spots
1console.log(word(0));
2let word = "cat";

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Hyena' badge — Savannah Debugger, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Does word[0] access the first character of a string?
A. Yes ✓
B. No
Strings are indexed starting at 0, just like arrays.
2. Does .length give the number of characters in a string?
A. Yes ✓
B. No
length counts every character in the string, including spaces.
3. Is () used instead of [] to access a character?
A. Yes
B. No ✓
Square brackets [], not round brackets, access a character by index.
4. Does .length need parentheses after it, like .length()?
A. Yes
B. No ✓
length is a property, not a method, so no parentheses are needed.
5. Is 'Length' with a capital L valid JavaScript syntax?
A. No ✓
B. Yes
JavaScript is case-sensitive, so it must be lowercase 'length'.

Match the Pairs

word[0] → Accesses the first character of the word string
word.length → Gives the total number of characters in word
Accesses the second character of a string → name[1]
A property that never needs parentheses → length
console.log(word(0)); → Wrong - use square brackets, not round brackets
console.log(word.length()); → Wrong - length is a property, not a method

Key Term

length
The number of characters in a string, accessed as a property without parentheses.

Fill in the Blanks

1. console.log(word[0]);
Hint: Type the symbol that opens an index access.
2. console.log(word.length);
Hint: Type the property that gives a string's number of characters.
3. let ch = word[1];
Hint: Type the index of the second character.
4. let name = "Amy"; console.log(name.length);
Hint: Type the property that gives a string's number of characters.
5. let size = name.length;
Hint: Type the property that gives a string's number of characters.

Spot the Error

Question 1
A console.log(word(0));
B let word = "cat";
C console.log(word.length);
Line A — Use square brackets [], not round brackets, to access a character.
Question 2
A let text = "dog";
B console.log(text(1));
C console.log(text.length);
Line B — Use square brackets [], not round brackets, to access a character.
Question 3
A let text = "cat";
B console.log(text.length);
C console.log(text0]);
Line C — Missing the opening square bracket before the index.
Question 4
A let word = "sun";
B console.log(word[0]);
C console.log(word.length);
D console.log(word[1);
Line D — Missing the closing square bracket after the index.
Question 5
A let name = "Amy";
B console.log(name[0]);
C console.log(name[1]);
D console.log(name[2]);
E console.log(name.lenght);
Line E — 'length' is misspelled as 'lenght'.

Student with a class code? Join your class →