String includes in JavaScript

Level 294 keystrokes

Uses includes() to check if a string contains a specific substring.

JavaScript code

// Create a string variable
1let str = "Hello World";
// includes() returns true if the substring is found
// "World" is in "Hello World", so it returns true
2console.log(str.includes("World"));
// "xyz" is not in the string, so it returns false
3console.log(str.includes("xyz"));

Output

true
false
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this JavaScript code and how often they appear.

  • "× 6
  • .× 4
  • (× 4
  • )× 4
  • ;× 3
  • =× 1

More JavaScript examples at level 2

← JavaScript typing practice