2 - Strings 1
2 - Strings 1
html
Strings I
Note that .length should not have () after it because it is a property (a value that has already been computed).
Whereas .toLowerCase() is a method that requires the () because it's an action that you are performing
Since 2022, JavaScript now has a .at() method that reads the character at a certain index, which can also be
negative
const language = "JavaScript";
language.at(0); // "J"
language.at(1); // "a"
language.at(-1); // "t"
language.at(-2); // "p"
You can also combine the character access with the .length property. So using the same language variable,
here's how you get the second to last character from it:
language[ language.length - 2 ]; // "p" because it's the second to last character from "JavaScript"
language[ language.length - 2 ]; // "p" because it's the second to last character from "JavaScript"
Note to self: Just a lil reminder, because it's always cool to remember =)
Interpolation
Template strings support interpolation! This means you could write a variable in your string, and get its
value. The syntax is straightforward, you wrap your variable name with a dollar sign and curly braces. Let's
take an example where we have a variable language with a value of JavaScript.
1 de 1 5/6/2025, 8:10 AM