Viewers: in countries Watching now:
- Creating variables, functions, and loops
- Writing conditional code
- Sending messages to the console
- Working with different variable types and objects
- Creating and changing DOM objects
- Event handling
- Working with timers
- Building smarter forms
- Using regular expressions
Multiple words are not separated with underscores as they might be in some other programming language. Functions are named the same way, or methods if they're in an object. Now, these are typically multiple words for clarity and often in a loose verb noun format. Think of the way that we work with the DOM: createElement, appendChild, getElementById. When we're working with objects, the convention here is to also capitalize the first word.
If there is one statement after the if and the condition, it behaves as if there are curly braces around it. But, as in other C-based languages, it's a really bad idea to do this, because later on it's super easy to add a line of code to this. And when you read this code what you think you're getting is this kind of block, where if x is more than 500 we're going to execute these two lines, but if we left the braces off, what we're actually getting is this.
If the condition is true, we will pop up the alert and we will always then go ahead and reset everything. And these kind of bugs can be a real pain to recognize, so always use the curly braces, even for one-line blocks. Now, another general rule here is even though you don't have to define your functions before you call them--so, for example, here I've got one function called some function that called other function, and other function is nicely defined after it in our code file-- the preference and the best practice is to define your functions before they are called.