← JavaScript

String Search Methods

Checks whether a string contains a given substring, returning true or false.

Understanding String Search Methods in JavaScript

What it does: indexOf() returns -1 when the substring doesn't appear. This tests whether "cat" appears anywhere inside word. includes() checks for a substring and returns a boolean result. indexOf() returns a position number, not true or false. JavaScript uses camelCase, so it must be indexOf. Both includes() and indexOf() need a value to search for. JavaScript is case-sensitive, so it must be lowercase 'includes'. includes() is used to test whether a substring exists.

Common mistakes: 'includes' must be lowercase - a capital I causes an error. Method names are camelCase - it should be indexOf, not indexof.

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 31–40) 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 includes() return true or false?
YesNo
Matches
text.Includes("world")
↓
Wrong - 'includes' must start with a lowercase i
Applying
Meanings
Term
includes()
Meaning
Checks whether a string contains a given substring, returning true or false.
Practice
let text = "hello world";
Testing
Gaps
console.log(text.("world"));
Check Answer
Spots
1let a = "hi there";
2console.log(a.Includes("hi"));

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

The 'Deer' badge — Forest Streak, 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 includes() return true or false?
A. Yes ✓
B. No
includes() checks for a substring and returns a boolean result.
2. Does indexOf() return a boolean like includes() does?
A. Yes
B. No ✓
indexOf() returns a position number, not true or false.
3. Does indexOf() return -1 when the substring isn't found?
A. Yes ✓
B. No
-1 signals that the substring doesn't appear in the string.
4. Is 'indexof' with a lowercase o valid JavaScript syntax?
A. Yes
B. No ✓
JavaScript uses camelCase, so it must be indexOf.
5. Do these search methods need a substring passed as an argument?
A. Yes ✓
B. No
Both includes() and indexOf() need a value to search for.

Match the Pairs

text.includes("world") → Returns true if text contains "world"
text.indexOf("world") → Returns the position where "world" starts in text
The value returned when a substring isn't found → -1
Checks whether a substring exists in a string → word.includes("cat")
text.Includes("world") → Wrong - 'includes' must start with a lowercase i
text.indexof("world") → Wrong - method names are camelCase: indexOf

Key Term

includes()
Checks whether a string contains a given substring, returning true or false.

Fill in the Blanks

1. console.log(text.includes("world"));
Hint: Type the method that checks if a string contains a substring.
2. console.log(text.indexOf("world"));
Hint: Type the method that returns the position of a substring.
3. let found = word.includes("cat");
Hint: Type the method that checks if a string contains a substring.
4. let pos = word.indexOf("cat");
Hint: Type the method that returns the position of a substring.
5. let hasDog = text.includes("dog");
Hint: Type the method that checks if a string contains a substring.

Spot the Error

Question 1
A let a = "hi there";
B console.log(a.Includes("hi"));
C console.log(a);
Line B — 'includes' must be lowercase - a capital I causes an error.
Question 2
A let b = "good day";
B console.log(b);
C console.log(b.indexof("day"));
Line C — Method names are camelCase - it should be indexOf, not indexof.
Question 3
A let c = "hi there";
B console.log(c);
C console.log(c.includes);
Line C — Missing parentheses and the search value - includes() needs an argument.
Question 4
A console.log(d.indexOf);
B let d = "good day";
C console.log(d);
Line A — Missing parentheses and the search value - indexOf() needs an argument.
Question 5
A let e = "hi there";
B console.log(e.includes("hi"));
C console.log(e);
D console.log(e.Includes("hi"));
Line D — 'includes' must be lowercase - a capital I causes an error.

Student with a class code? Join your class →