1 00:00:00,025 --> 00:00:07,643 [SOUND] There's a saying that the best code is no code at all. 2 00:00:07,643 --> 00:00:12,390 Which is to say the more code we write, the more likely we are to introduce a bug. 3 00:00:12,390 --> 00:00:14,570 The more code browsers need to download, and 4 00:00:14,570 --> 00:00:18,560 the longer it can take to review your own in your colleague's program. 5 00:00:18,560 --> 00:00:22,010 In other words, writing less code is often a good thing. 6 00:00:22,010 --> 00:00:26,950 One short ES2015 gives us is the object property shorthand. 7 00:00:26,950 --> 00:00:30,050 It's a simple, but very useful addition to JavaScript. 8 00:00:30,050 --> 00:00:30,820 Let's see it in action. 9 00:00:32,040 --> 00:00:35,670 You can follow along using the latest workspace by opening the workspace for 10 00:00:35,670 --> 00:00:36,215 this video. 11 00:00:36,215 --> 00:00:41,560 Suppose I have a form that allows students to submit feedback about a course. 12 00:00:41,560 --> 00:00:45,218 The form has three fields, name, comments and rating. 13 00:00:45,218 --> 00:00:49,640 Over in shorthand.js, I have a submit function 14 00:00:49,640 --> 00:00:55,080 that will compose the data object that eventually gets sent to the server. 15 00:00:55,080 --> 00:01:01,440 The function also logs the keys of data and the values passed in this four loop. 16 00:01:01,440 --> 00:01:03,940 And you might have noticed that the object 17 00:01:03,940 --> 00:01:06,450 assigned to the data variable looks a bit different. 18 00:01:06,450 --> 00:01:08,540 There aren't any keys. 19 00:01:08,540 --> 00:01:14,680 Well, ES 2015 provides a shorter syntax for defining property keys and objects. 20 00:01:14,680 --> 00:01:19,240 When the interpreter encounters a variable assignment without a property key, 21 00:01:19,240 --> 00:01:23,160 the variable name itself is used as the property key. 22 00:01:23,160 --> 00:01:27,320 So I'll call the submit function and pass it some values. 23 00:01:28,990 --> 00:01:31,340 For name, let's type English. 24 00:01:32,630 --> 00:01:36,510 And for comments, let's pass great course. 25 00:01:39,610 --> 00:01:44,253 When I run this file in the console, you can see that the key names match 26 00:01:44,253 --> 00:01:47,966 the variable names we passed to the object definition. 27 00:01:51,008 --> 00:01:56,030 And you're not limited to string values as we used here. 28 00:01:56,030 --> 00:02:00,210 It's also possible to use this new feature with booleans, numbers, objects, 29 00:02:00,210 --> 00:02:02,180 arrays and classes. 30 00:02:02,180 --> 00:02:05,870 So, for instance, if I set the rating to nine. 31 00:02:08,760 --> 00:02:10,810 The console returns a rating of nine. 32 00:02:12,290 --> 00:02:16,640 As you learned, property shorthand is easy to use, reduces keystrokes, and 33 00:02:16,640 --> 00:02:19,400 potentially reduces bugs in your code. 34 00:02:19,400 --> 00:02:22,670 In the next video, I'll go over the new for of syntax.