We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Strings

In JavaScript, a (non-template) string can be written with either single or double quotes. For example:

  • 'Hello'
  • "Hello".

Personally, we prefer double quotes! It's important to have styling conventions so that all the code in a project looks consistent, making it easier to read and contribute to.

Indexing

Square brackets are used to access individual characters inside a string. The characters are numbered from 0 to length-1. It's similar to how strings and lists work in Python, Go and many other languages.

const greeting = "Hello";
console.log(greeting[0]); // 'H'
console.log(greeting[1]); // 'e'
console.log(greeting[2]); // 'l'
console.log(greeting[3]); // 'l'
console.log(greeting[4]); // 'o'
// you can also get the last char at length-1
console.log(greeting[greeting.length - 1]); // 'o'

The .length property is used to get the number of characters in a string.

Assignment

Follow the instructions in the comments on lines 3, 5, and 7 to log information about one of Textio's user's email addresses.