Hello! Today, we're going to explore some key JavaScript string operations: concatenation, slicing, charAt, includes, indexOf, toLowerCase, and toUpperCase. We'll unlock these skills through examples.
Strings in JavaScript are used to store and manage text. To create a string, you can use single quotes (' '), double quotes (" "), or backticks (``). Here's an example:
In the example above, each of the variables firstName, lastName, and job holds a string.
Concatenation combines strings. In JavaScript, we use the + operator for this task. It's like merging puzzle pieces. Consider the following example:
In the example above, we've combined two strings to form a new string: 'Welcome to Mars!'.
Slicing involves extracting a substring (a part or segment of the string). The substring(from, to) method in JavaScript facilitates this task - it returns the substring constructed from characters at positions from, from + 1, ..., to - 1, i.e., you start from the character at the position from, and end at to, excluding it.
A version of this method substring(from), at the same time, just takes the substring from the provided character till the end.
Let's see how it works:
