Skip to the content

Indexing text

JavaScript · Unit 6: Strings

A string is a row of characters, like an array of letters.

length says how many it has, and [i] takes the one at that position, counting from 0.

const name = "Jordan";
console.log(name.length);
console.log(name[0]);
console.log(name[1]);

Prints

6
J
o

The rest of the explanation is in the lesson, which is part of the full plan.

Exercises in this lesson

You do them in the app, which checks them on the spot and explains why.

  1. 1. Predict the output

    What does this code print?

  2. 2. Predict the output

    Spaces are characters too. What does it print?

  3. 3. Complete the code

    Complete it to print the last letter of "Emily".

  4. 4. Predict the output

    What does this code print?

  5. 5. Complete the code

    Complete it so it prints the month, "09".

  6. 6. Multiple choice

    What does this code do?

  7. 7. Find the bug

    This program should print "Jason" with a capital J. Which line has the error?

  8. 8. Predict the output

    What does this code print?

  9. 9. Put the lines in order

    Order the function that hides a phone with * and shows only the last 4 digits.

  10. 10. Find the case that fails

    initial(name) should return the first letter of the name, or an empty string "" if the name is empty. Which call breaks it?

Do this lesson

It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.

See all lessons →