 A function in JavaScript can be created with a function statement, which begins with a reserved word function, followed by the name of the function, then a comma-separated list of parameters in parentheses, and then a body enclosed in curly braces. What you see here is the most common formatting style, but again, JavaScript's freeform syntax allows for many formatting variations. So here we create a function with the name Helen, give it two parameters, apple and orange, and have it simply return the sum of the two parameters. Then invoke the function with the arguments 3 and 5 and assign the return value to a new variable, Dan. An important thing to understand about a function statement is that it effectively doubles as an assignment statement, because the name given for the function is actually just an ordinary variable. Here the function statement creates a new function value and assigns it to the variable Helen. If no variable Helen has yet been declared, the function statement implicitly declares it. A function in JavaScript can also be created as an expression, an expression which returns the new function as a value. The expression form has the same syntax as the statement form, except that we don't specify any name. So here we have an expression creating the exact same function as our previous example. For clarity, I have surrounded the function expression in orange parentheses, though the parentheses are not required. This expression in the parentheses returns a function value just like the one created by the function statement, and then that value is assigned here to the variable Helen. So this code is actually precisely equivalent to our statement form example. The only difference is stylistic. Notice that JavaScript's free form syntax comes in handy here because it allows us to approximate the usual indentation style of a function, even though we're writing the function in the middle of an assignment statement. Again, be clear that some programmers prefer to format functions differently, but this is the most common style. Now, when we create a new function and assign it to a variable, the statement form is obviously the most convenient form. But in some cases, we want to create a new function without assigning it to a variable. For example, we might wish to create a function simply to pass it as argument to some other function. In such cases, the expression form is more convenient because it allows us to create a function without having to give it a name. Like the arithmetic operators, the logical operators in JavaScript are symbols, not reserved words as they are in pigeon. The AND operator, for instance, is written as two ampersands, the OR operator is written as two pipe symbols, and the NOT operator is written as an exclamation mark. The Equality Test operator can actually be written as just two equal signs instead of three, but three is usually the better choice because of a quirk of the language we'll discuss later. In JavaScript, the values null, zero, and empty string and undefined are all considered to have the truth value false. This means that for the sake of logical operations and condition tests, like of an if or a while, these values are treated the same as the boolean value false itself. All other values, though, are treated the same as the boolean value true. Here then, NOT true of course returns false, and NOT false returns true, but NOT null, NOT zero, NOT empty string, and NOT undefined all return true as well, because those values themselves are all considered false for the sake of any logic operation. Again, all values other than these five are considered true. Here the first line returns true because three is equal to three, the second line returns false because three is NOT equal to negative two, and the third line returns true because the NOT operator has the higher precedence. NOT true returns false, and then false is equal to false returning true. This expression tests whether three is equal to three or two is greater than four, and of course three is equal to three. So even though two is not greater than four, the OR operation returns true because one of its operands is true. Note that the parentheses here could have been left out because the equals operator and the greater than operator both have higher precedence than the OR operator, and so would have been done first anyway. For stylistic reasons though, it's often good to use superfluous parentheses to make the order of operations absolutely clear. If, else, and while in JavaScript differ only in syntax from their counterparts in Pigeon, the conditions must always be written enclosed in parentheses, and the bodies are always written enclosed in curly braces. Also note that there's no reserved word eleph, instead you write else space if. So for instance, here we have an if else with a condition x equals three, and so when x does not equal three, the function foo is called, otherwise the function bar is called. For this while loop, first we declare counter variable i with the initial value zero, then the condition tests whether i is less than five, and then inside the loop we call the function foo, and then increment the variable i by one. So this loop will call foo five times. When inside a function we use a variable name which has not been declared inside that function, JavaScript assumes that the name refers to a global instead of a local. Here for instance, the function foo declares no local of the name bar, so JavaScript assumes that bar in the return statement refers to a global. However, executing this return statement when a global bar does not actually exist will trigger an error. So here, the call to foo after the function will trigger an error, assuming no global named bar was previously created. Here though we create a global bar before calling foo, and so the code runs fine without error. Unsurprisingly, a global must already exist when we try to use it. When functions use globals though, those globals don't have to exist by the time the function is created, only by the time they are used when the function is called. In contrast to globals, local variables can be declared anywhere in a function just as long as we put the declaration somewhere in the function. Here the declaration of bar comes after the return statement where execution will never reach, but local variable declarations aren't really executed, they simply exist. Local variable declarations are not really actions in the flow of execution, they simply annotate the set of local variables that exist in that function. So we could put this declaration of bar anywhere in the function we like. Common practice though is to simply put all local declarations at the very start of the function.