Variables

 

Main Topics

  1. No spaces in the name
  2. No digits in front
  3. Underscore are ok, but they are not encouraged
  4. Dollar signs are ok, but they are not encouraged
  5. Begin with lowercase and then camel case 
Variables  can be declared using the "var" modifier

Sample

var myVariable   = 3
var myVariable2 = "The content of the variable"

Once the variable has been defined with the "var" modifier, there is no need to use the modifier again to alter the content of the variable

myVariable2 = "Some other content"

Variables can be incremented o decremented if they have a numerical value, it can be done with the ++ or -- symbols

Sample

var myNumericalVariable1 = 1
var myNumericalVariable2 = 1

myNumericalVariable++           // This outputs "2"
myNumericalVariable--             // This outputs "0"

There are several different ways to change the content of a variable, some of the ways to change variables that contains numerical values are:

Suppose we have already declared the variable : myVariable

Operations

myVariable += 2  // makes a pre-adding operation with the current value of myVariable and 2, and then assign the result to myVariable

myVariable -= 3   // makes a pre-subtract operatin with the current value of myVariable and 3, and then assign the result to myVariable 

myVariable *= 2  // makes a pre-multiply operation with the current value of myVariable and 2, and then assign the result to myVariable

myVariable /= 3   // makes a pre-dive operatin with the current value of myVariable and 3, and then assign the result to myVariable