The value of a variable can change

Arithmetic operators

The arithmetic operators in JavaScript are the same as the ones used in mathematics. So we have the +, -, * and / operators.
Also in JavaScript the modulus is symbolized with %. The modulus operator gives the remainder of the division. It is only applied to Integers. For example, 7%6 will give us 1.
++ and – are used for increment and decrement respectively.

Assignment operators

In JavaScript, we also have the assignment operators.

These are:

Assignment operators

var a = 0;
  a ++ ; /* a = a + 1, The Increment operator, 1 */
var b = 10;
  b --; /* b = b - 1, The Decrement operator, 9 */
var c = 50;
  c += 10; /* c = c + 10, 60 */
var d = "Hello";
  d += "!" /* d = d + "!" , Add (concatenate) strings, Hello! */
var x = a + b; /* The addition operator, 10 */
var y = a * b /* The Multiplication operator, 9 */
var z = a / b /* The Division operator, 0.1111111111111111 */
var w = a % b; /* The Modular operator (%) returns the division remainder, 1 */

Exercise

  1. Open your editor, create a new file and save it as exersice05.3.02.html in the folder "yourNameWEB2JS".
  2. Copy the following code and paste it into the new file.
  3. Complete the code and save the file. We want the console to display "x =13 y = 1 z = 30".

Code:

Answer:

var x = a + b; 
var y = a % b;
var z = a * b