- Control Flow is the order in which the computer executes statements in a script.
- Code is run in order from the first line in the file to the last line, unless the computer runs across the (extremely frequent) structures that change the control flow, such as conditionals and loops.
- A typical script in JavaScript or PHP (and the like) includes many control structures, including conditionals, loops and functions. Parts of a script may also be set to execute when events occur.
- Control flow means that when you read a script, you must not only read from start to finish but also look at program structure and how it affects order of execution.
- A JavaScript function is a block of code designed to perform a particular task.
- A JavaScript function is executed when “something” invokes it (calls it):
- When an event occurs (when a user clicks a button)
- When it is invoked (called) from JavaScript code
- Automatically (self invoked)
- When JavaScript reaches a return statement, the function will stop executing.
- If the function was invoked from a statement, JavaScript will “return” to execute the code after the invoking statement.
- Functions often compute a return value. The return value is “returned” back to the “caller”
- Arithmetic operators are used to perform arithmetic on numbers
- Assignment operators assign values to JavaScript variables.
- String Operators:
- The + operator can also be used to add (concatenate) strings.
- When used on strings, the + operator is called the concatenation operator.
- The += assignment operator can also be used to add (concatenate) strings
- Adding two numbers, will return the sum, but adding a number and a string will return a string
- If you add a number and a string, the result will be a string!
- Comparison and Logical operators are used to test for true or false.
- Bitwise Operators:
- Bit operators work on 32 bits numbers.
- Any numeric operand in the operation is converted into a 32 bit number. The result is converted back to a JavaScript number.
Further References: