Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
JAVASCRIPT TEXT / CHAPTER 03 / Learn / LESSON 01
Text chapter. Foundations showed template literals; Data showed arrays. Now the string is the main character: a sequence of characters.
Every character has an index starting at 0. The first is text[0], the second text[1]. Length is text.length (a number). The last character is often text[text.length - 1].
Square brackets read one character. This goes deeper than “just glue text together” from Foundations.
Mini example:
const tag = "food"; console.log(tag[0]); console.log(tag.length); console.log(tag[tag.length - 1]);
Common mistake: expecting text[1] to be the first character; or confusing length with the last index (length is the count; the last index is length - 1).
Brackets read a character; length is the count.
DATA STANDBY
›