Read: 04a - Dynamic web pages with JavaScript:

Control flow

The control flow is the order in which the computer executes statements in a script.

Control flow

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.


JavaScript Operators:

JavaScript has different kinds of operators:

Arithmetic Operators such as:

Assignment Operators

Assign values to JavaScript variables.

such as: The addition assignment operator (+=) adds a value to a variable.

String Operators

The + operator can also be used to add (concatenate) strings.

Example:

var txt1 = “What a very “;

txt1 += “nice day”;

The result of txt1 will be:

What a very nice day

Adding Strings and Numbers

Adding two numbers, will return the sum, but adding a number and a string will return a string:

Comparison Operator

Operator Discription
== equal to
=== equal value and equal type
!= not equal
!== not equal value or not equal type
> greater than
< less than
>= greater than or equal to
<= less than or equal to
? ternary operator