[go: up one dir, main page]

0% found this document useful (0 votes)
7 views1 page

2 - Strings 1

The notes cover key concepts in JavaScript strings, including the use of .length as a property and .toLowerCase() as a method. It introduces the .at() method for character access and explains substring extraction using string.substring(). Additionally, it highlights template strings for interpolation, allowing variables to be included in strings using the ${variableName} syntax.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

2 - Strings 1

The notes cover key concepts in JavaScript strings, including the use of .length as a property and .toLowerCase() as a method. It introduces the .at() method for character access and explains substring extraction using string.substring(). Additionally, it highlights template strings for interpolation, allowing variables to be included in strings using the ${variableName} syntax.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

My notes https://learnjavascript.online/app.

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:

const language = "JavaScript";

language[ language.length - 2 ]; // "p" because it's the second to last character from "JavaScript"

const language = "JavaScript";

language[ language.length - 2 ]; // "p" because it's the second to last character from "JavaScript"

A substring is a part or a portion of a string.


string.substring(indexStart, indexEnd) is used to return a portion of the string.
indexStart: the position of the first character you'd like to include.
indexEnd: the position of the first character you'd like to ignore.
the indexEnd argument is optional which means you can leave it out.
The + operator is used to add 2 numbers
The + operator is used to concatenate 2 strings

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.

let language = "JavaScript";


`I am learning ${language}`; //"I am learning JavaScript";

A template string is a string created with the backtick character: `


Template strings can span multiple lines
Template strings support interpolation with the ${variableName} syntax
Show previous notes

1 de 1 5/6/2025, 8:10 AM

You might also like