Learn how a string means characters: words, letters, sentences.
- [Narrator] In this video we're going to look at strings. A string is character data meaning things like sentences, words, single letters, numbers, or punctuation. Basically it means anything between quote marks. So, for example, I could say, "This is a string". Chrome highlights it in red for me. When you formulate a string like this, it's actually called a string literal. Literal here basically means you're making data of some type using the simplest notation possible. So making a string literal like this, means I'm putting string data inside quote marks.
To fix this, I need to use a backslash to do what's called escaping the string. So I'm going to put a backslash in front of each of these quotes that's supposed to be an inside of this entire string. So for every quote mark that's causing trouble I add that slash. Just to prove this works I'm going to select this, copy it, return to the browser, paste it in. There, it works. And it's printed without those backslash marks which is a little bit confusing. I couldn't just copy this and re-execute it, it won't work.
As you can see, this is turning black again. Backslashes let us do one more helpful thing, breaking string up into multiple lines. So I'll switch back to my editor and if I want to write another string called "This is Joe's favorite String EVER" I've got all these squiggly lines telling me that this is not working. But if I put a backslash on the end of each line, I'm putting a little extra space in there just to make it a little more readable, all the squiggles go away, the whole string is highlighted in red.
And then I just end the string with the same kind of quote mark that I started it with. For something this short it doesn't really matter but when you need really long runs of text this can be pretty helpful. So that's an overview of how to create strings which are character data or things like sentences, words, and so forth.
- Using a text editor
- Declaring and assigning variables
- Booleans and the quest for truth
- Working with objects and arrays
- Using operators and control structures
- Iterating with loops
- Objects, references, and functions
- Promises, async, and await