String Slice in JavaScript

Level 283 keystrokes

Uses slice() to extract parts of a string by specifying start and end positions.

JavaScript code

// Create a string variable
1let text = "JavaScript";
// slice(start, end) extracts characters from start to end-1
// slice(0, 4) extracts characters at positions 0, 1, 2, 3 = "Java"
2console.log(text.slice(0, 4));
// With only start, slice(4) extracts from position 4 to the end = "Script"
3console.log(text.slice(4));

Output

Java
Script
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.

  • .× 4
  • (× 4
  • )× 4
  • ;× 3
  • "× 2
  • ,× 1
  • =× 1

More JavaScript examples at level 2

← JavaScript typing practice