1 00:00:00,670 --> 00:00:04,170 So variables are like boxes that you can store information in. 2 00:00:04,170 --> 00:00:07,230 But what exactly are we storing? 3 00:00:07,230 --> 00:00:10,960 We call the information we put in a variable a value, and 4 00:00:10,960 --> 00:00:13,600 values come in many different types. 5 00:00:13,600 --> 00:00:14,200 At this point, 6 00:00:14,200 --> 00:00:19,300 we're going to learn about two common value types, numbers and strings. 7 00:00:20,470 --> 00:00:22,880 Numbers are used for making calculations, adding, 8 00:00:22,880 --> 00:00:27,330 subtracting, computing total costs, keeping track of a game score and so on. 9 00:00:27,330 --> 00:00:31,630 I'll talk a lot more about them in the next stage of this course. 10 00:00:31,630 --> 00:00:34,940 Strings are used for words, sentences, and other text. 11 00:00:34,940 --> 00:00:38,880 You've already seen strings in action when we use the alert command. 12 00:00:38,880 --> 00:00:41,690 The message hello from treehouse is called a string. 13 00:00:41,690 --> 00:00:44,780 A string is just a series of letters, numbers and 14 00:00:44,780 --> 00:00:47,910 other characters inside of quote marks. 15 00:00:47,910 --> 00:00:50,030 All of these are examples of strings. 16 00:00:53,500 --> 00:00:56,300 The quote marks tell the JavaScript interpreter that it 17 00:00:56,300 --> 00:00:59,380 should treat the contents inside as just a set of 18 00:00:59,380 --> 00:01:02,500 characters without any special meaning to the browser. 19 00:01:03,700 --> 00:01:06,410 You'll use strings all the time when programming. 20 00:01:06,410 --> 00:01:09,760 Each time you wanna add a message to a web page, pop up an alert or 21 00:01:09,760 --> 00:01:14,370 collect information from a web form you'll be dealing with strings. 22 00:01:14,370 --> 00:01:18,490 JavaScript lets you use either double or single quotes to create a string. 23 00:01:18,490 --> 00:01:20,210 Just be consistent. 24 00:01:20,210 --> 00:01:22,800 If you begin a string with a single quote you need to 25 00:01:22,800 --> 00:01:25,240 end the string with a single quote. 26 00:01:25,240 --> 00:01:28,970 Likewise if you begin a string with a double quote you need to end it 27 00:01:28,970 --> 00:01:29,830 with a double quote. 28 00:01:31,690 --> 00:01:35,780 Things get a little tricky when you want to put a quote mark inside a string. 29 00:01:35,780 --> 00:01:40,170 If you wanted to put she's a great person in a string you need to look out for 30 00:01:40,170 --> 00:01:42,630 the single quote mark in she's. 31 00:01:42,630 --> 00:01:46,810 For example, you'll encounter a syntax error if you type this. 32 00:01:48,670 --> 00:01:51,050 The single quote starts the string. 33 00:01:51,050 --> 00:01:55,030 But the next single quote in she's ends the string, 34 00:01:55,030 --> 00:01:58,090 at least according to the browser's JavaScript interpreter. 35 00:01:58,090 --> 00:02:01,200 So the rest of the characters are outside the string and cause an error. 36 00:02:02,370 --> 00:02:06,310 A simple solution is to use double quotes to create a string that has one or 37 00:02:06,310 --> 00:02:07,520 more single quotes in it. 38 00:02:08,650 --> 00:02:13,030 Because the first quote mark is a double quote, the JavaScript interpreter won't 39 00:02:13,030 --> 00:02:16,260 end the string until it finds the next double quote mark. 40 00:02:17,320 --> 00:02:20,473 Likewise, you can use single quotes to create a string whenever you 41 00:02:20,473 --> 00:02:22,309 need double quotes inside the string. 42 00:02:22,309 --> 00:02:26,538 [BLANK_AUDIO] 43 00:02:26,538 --> 00:02:29,540 There's another way to put a quote into a string. 44 00:02:29,540 --> 00:02:32,610 You can use what's called an escape character. 45 00:02:32,610 --> 00:02:37,830 If you put a backslash before the quote mark, the JavaScript interpreter simply 46 00:02:37,830 --> 00:02:42,090 treats the quote mark like any other character with no special power. 47 00:02:42,090 --> 00:02:45,500 It's literally just a quote mark character at that point. 48 00:02:45,500 --> 00:02:49,080 You can use the backslash before either single or double quote marks.