# Strings

# What is a String Object

The String Object has the value of its Primitive as well as one property and a long list of methods. The methods are actions that you can use to change or examine the value of the String.

We will use dot notation to access any property or method on the String.

# String length Property

Strings only have one property - their length.

let name = 'Ricky Bobby';
console.log(name.length);
1
2

# Concatenating Strings

When you need to combine multiple strings or put together strings and variables, there are three ways to do this. With the concatenation operator +, with the String concat() method, or by using Template Strings.

# String Methods

In JavaScript you will often find that the terms function and method are used interchangeably.

# Template Strings

Up until now we have been using single and double quotes to wrap our Strings.

Since ES6, there has been a third way to wrap strings - the Template String - with the backtick character.

let name = 'Waldo';
let str = `Hello, my name is ${name}.`;
console.log(str); // Hello, my name is Waldo.
1
2
3

Template strings let us put variables inside the string. We just need to wrap the variable inside ${ }. While this may seem complicated, it is actually much easier to type than the original way of doing this.

let name = 'Waldo';
let str = 'Hello, my name is ' + name + '.';
console.log(str);
1
2
3

Each time you wanted to combine a variable as part of a string you had to end the string with quotation marks, add a plus sign, then the variable, then start the string up again.

Back to Week 3 main page

Last Updated: 10/20/2020, 12:37:52 PM