Reading notes about code for my future reference.
###Control Flow
The control flow is the order in which the computer executes statements in a script.
(HOW THE PC READS CODE AND WHICH ORDER)
The if function will go first followed by the else due to rules and conditional structures!
if (isEmpty(field)) {
promptUser();
} else {
submitForm();
}
Javascript includes many control structures and conditionals
Loops
Functions!
Parts of a script may also be set to start events when they happen!
Control structures can dictate flows of how code and script run. EVEN if they are only a few lines long.
Javascript function is a block of code designd to peform a particular task.
A javaScript function is executed when it gets trigged by something or called!
A JavaScript function is defined with the function keyword, followed by a name, followed by parentheses ().
Names can contain letters, digits, under scores, and dollar signs (same rules as variables!)
Paratheses can include parameter names by seperating them with commas.
The code inside the function will execute when “something” invokes (calls) the function.
Example of Function Returns
You can reuse code: Define the code once, and use it many times.
You can use the same code many times with different arguments, to produce different results.
Accessing a function without () will return the function object instead of the function result.
Function used as variable values!
Functions can be used the same way you use
Assignment
let x = 10;
Adding let x = 5;
let y= 2;
let z = x+y;
Multiplying
let x = 5;
let y = 2;
let z = x * y;
The + operator can combine string!
let text1 = “John”;
let text2 = “Doe”;
let text3 = text1 + “ “ + text2;
let x = 5 + 5;
let y = “5” + 5;
let z = “Hello” + 5;
Javascript Comparison Operators