Some JavaScript Syntax Video Lecture Transcript This transcript was automatically generated by Zoom, so there may be discrepancies between the video and the text. 17:32:30 Hi! Everybody! Welcome back in this video. We're gonna talk about some Javascript syntax for some very common coding tabks that you'd encounter. 17:32:40 So this is really more of a reference point. So if you find yourself needing to write something like a for loop or an if else statement, you'll want to reference this back, or just do a web, search for it. 17:32:51 So feel free to skip this if you don't think you need it, but if you're interested in seeing the syntax for these things within Javascript feel free to stick around, so we are gonna use functions a lot within our D 3 dot Js code so the syntax for writing a 17:33:05 function, within within Javascript is function. You. 17:33:13 This is a keyword function, followed by function, name, followed by parentheses with whatever inputs you'd like. 17:33:20 So like x comma y comma z, and then brackets, and within the brackets you write whatever you want. 17:33:26 The function to do, and then you'll return if you want something, returned. 17:33:31 And then, after the function, you put a semicolon. 17:33:34 So this is the syntax. If you want to define a function that you're gonna call again later. 17:33:39 So maybe I want to function where I'm going to multiply whatever it is by 2. 17:33:44 So you'd put like X, and then return 2 times X you're gonna call an anonymous function. 17:33:49 You would just put function, followed by the inputs without the name. In the middle. 17:33:55 So you can call function without the name, and then that will just be an anonymous function that runs right away. 17:34:02 And if statement is written by writing, if, then, in parentheses, whatever your logic condition is so like, if X is less than 2, and then brackets whatever you want executed. 17:34:16 If else is you just add an else after that, with brackets, and then whatever you want executed. 17:34:22 If the if statement isn't true. 17:34:26 Then you can do, if else, if by just adding an if after the else, with the logical condition, and then whatever you want executed, so you can chain all these things together to have whatever logic you want followed so there's a couple ways to do for loops so for the first for loop you'll 17:34:46 do 4, and then, followed by 3 expressions, then brackets, and whatever code you want to run each time through the loop. 17:34:53 So expression, one would be defining the loop variable. 17:34:57 And it's starting value. So, for instance, you could be let. 17:35:00 I equals 0. Which means your thing, your looping variable is I, and it starts at 0. 17:35:07 Then expression. 2 would be the logical condition for exiting the loop, so as long as I is, for instance, less than 10, you keep going through, and then expression 3 would be the updating each time through the loop. 17:35:22 So if you want to increase, I by one, you do. 17:35:26 I equals I plus one. So you'd say, like 4, let I equals 0. 17:35:30 I less than 10 I equals I plus one. It would go through until eventually I is equal to greater than or equal to 10. 17:35:40 Another way to write a for loop is to loop through some items within an object. 17:35:45 So you do. 4 in parentheses, key in object where you would replace with the relevant names. 17:35:52 And then, whatever code you want to run. So this would be like 4 in Pipthon. 17:35:58 This is like 4 x in list isn't an example. 17:36:03 Okay, so those are some of the most common coding tasks that you need. Right? 17:36:07 So you need functions, if else, and then for loops. 17:36:12 So now this is you've seen the syntax of how to do that. 17:36:14 These will come up again, as we learn. D 3 dot js, because inevitably you're going to need. 17:36:20 If you're writing Javascript, you need to know how to write in Javascript. 17:36:25 Okay, so that's it for this video. I hope you enjoyed seeing the syntax. 17:36:27 If you stuck around and I can't wait to see you next time where we learn a little bit more about Javascript.