If you have created your own variables and assigned them each a value (such as a string or integer), then you will already be familiar with the assignment operator which is a single = (equals sign).

There are other operators used for calculations though such as adding, subtracting, multiplying, dividing, increasing and decreasing values, etc. Take a look at the source code to see what is available.

Make sure you also watch the video about operators here.

<!DOCTYPE html> <html lang="en" <head> <meta charset="utf-8"/> <title>JavaScript - Operators</title> <script type="text/javascript"> var x = 5, y = 10; //variables can be initialised on one line, separated by commas var z = x + y; // this is how variables can be added z++ //this increases the z variable value by 1 z-- //this decreases the z variable value by 1 // operators include + (plus) - (minus) * (multiply) / (divide) and % (modulus) which returns the remainder from division x+=y; //this is an example of compound addition. It is the equivalent of x = x + y // variables can be added using the compound addition += , compound subtraction -= , compound multiplication *= or compound addition /= document.write(z); // now let's see what the z variable displays after these modifications. </script> </head> <body> </body> </html> |