1 00:00:00,440 --> 00:00:04,590 The let keyword is used when you want to re-assign a variable. 2 00:00:04,590 --> 00:00:07,390 In that respect, It just works like var. 3 00:00:07,390 --> 00:00:09,758 Let's take a look at a simple example. 4 00:00:09,758 --> 00:00:16,738 Open up let.html, and you can see we've got the score = 0 and 5 00:00:16,738 --> 00:00:22,130 age = 33, and a boolean is hungry = false. 6 00:00:22,130 --> 00:00:28,070 Open up the preview and navigate to let.html. 7 00:00:28,070 --> 00:00:36,590 Open up the console, and let's try and modify the score. 8 00:00:36,590 --> 00:00:38,877 The score can change through a game. 9 00:00:38,877 --> 00:00:43,920 The score increments by one each time the player completes a challenge. 10 00:00:43,920 --> 00:00:47,308 Again, let just works like var. 11 00:00:47,308 --> 00:00:52,430 You can reassign values to a variable that is declared with the let keyword. 12 00:00:53,460 --> 00:00:57,266 You can update the age to be 34. 13 00:00:57,266 --> 00:01:00,763 And is hungry. 14 00:01:05,240 --> 00:01:07,787 To be true. 15 00:01:07,787 --> 00:01:14,305 Let's look at a more complex example where you should use let rather than a const. 16 00:01:14,305 --> 00:01:18,826 Open up person.html, and here we have a function called 17 00:01:18,826 --> 00:01:24,020 personDescription that creates a description string. 18 00:01:24,020 --> 00:01:27,890 That gets logged out at the end here. 19 00:01:27,890 --> 00:01:30,840 If the person object has a role, 20 00:01:33,410 --> 00:01:40,510 it will add additional information at the end of the description and is logged out. 21 00:01:40,510 --> 00:01:42,440 Let's see this in action. 22 00:01:42,440 --> 00:01:43,396 Go to the preview. 23 00:01:43,396 --> 00:01:46,910 Click on person.html, 24 00:01:46,910 --> 00:01:52,790 open up the developer console and we should see Andrew is a teacher. 25 00:01:52,790 --> 00:01:57,409 If we change the var keyword in the person description function to const. 26 00:01:59,420 --> 00:02:06,045 And run it again we get an error, because we're trying to re-assign the description 27 00:02:06,045 --> 00:02:12,128 in the if block, We could change it to var, 28 00:02:12,128 --> 00:02:16,200 or alternatively we could use the new let keyword. 29 00:02:18,980 --> 00:02:23,560 Let works like var, allowing you to re-assign variables, but 30 00:02:23,560 --> 00:02:26,980 unlike var, it has block level scoping. 31 00:02:26,980 --> 00:02:32,310 We'll explore when we'd see the advantages of using let over var in the next video. 32 00:02:32,310 --> 00:02:38,540 Now that we've changed the const to let, let's see how it works in our browser. 33 00:02:38,540 --> 00:02:42,930 Looking in the console, we see Andrew is a teacher printed out like we expect. 34 00:02:42,930 --> 00:02:43,820 In the next video, 35 00:02:43,820 --> 00:02:48,540 we'll look at how let solved some problems where the var keyword falls short.