operators and Loops

## Expressions and operators

  • Operators

    JavaScript has the following types of operators. This section describes the operators and contains information about operator precedence.
    **There are a lot type of operator like : **

  • Assignment operators
  • Comparison operators
  • Arithmetic operators
  • Bitwise operators
  • Logical operators .. etc.

Operator

Expressions

An expression is any valid unit of code that resolves to a value.

Every syntactically valid expression resolves to some value but conceptually, there are two types of expressions: with side effects (for example: those that assign value to a variable) and those that in some sense evaluate and therefore resolve to a value.

JavaScript has the following expression categories:

  • Arithmetic: evaluates to a number, for example 3.14159. (Generally uses arithmetic operators.)
  • String: evaluates to a character string, for example, “Fred” or “234”. (Generally uses string operators.)
  • Logical: evaluates to true or false. (Often involves logical operators.)
  • Primary expressions: Basic keywords and general expressions in JavaScript.
  • Left-hand-side expressions: Left values are the destination of an assignment.

expression


Loops and iteration

Loops offer a quick and easy way to do something repeatedly. This chapter of the JavaScript Guide introduces the different iteration statements available to JavaScript.

You can think of a loop as a computerized version of the game where you tell someone to take X steps in one direction, then Y steps in another. For example, the idea “Go five steps to the east” could be expressed this way as a loop

loop

There are many different kinds of loops we will focus at :

  • for statement :
    A for loop repeats until a specified condition evaluates to false. The JavaScript for loop is similar to the Java and C for loop.

    A for statement looks as follows:

** for ([initialExpression]; [conditionExpression]; [incrementExpression]) statement **

  • while statement:
    A while statement executes its statements as long as a specified condition evaluates to true.

A while statement looks as follows:

while (condition) statement