Lesson Weekend

You can call methods on strings, just like you can with numbers:

> "supercalifragilisticexpialidocious".toUpperCase();

Or even call the method on a variable assigned to a string:

> var word = "foo";
> word.concat("bar");

Methods can be chained like this:

> "foo".concat("bar").toUpperCase();

The concat() method (which concatenates, or combines, two strings) returns a string, which then has toUpperCase() called on it. Then, toUpperCase() returns the final result.

By the way, here's a nice shortcut for the concat() method:

> "I love" + " " + "Epicodus";
"I love Epicodus"

Or with variables:

> var sentiment = "I love ";
> var animal1 = "cats";
> var animal2 = "dogs";
> sentiment + animal1;
"I love cats"
> sentiment + animal2;
"I love dogs"

Back to arguments. String methods can take numbers as arguments, too:

> "caterpillar".charAt(5);

Did you notice something funny about this example? What's the fifth character of the word "caterpillar"? Well, with the way we normally count, "c" is the first letter, and "r" is the fifth. But JavaScript says that the character at the 5th position is "p". That's because computers start counting at zero. So "c" is the zeroth letter, and "r" is the fourth.