Operators are built in commands that combine, manipulate, or transform values.
We recently saw an example of using the + operator when we glossed over String Concatenation.
Get ready for operator overload...this is a lot to swallow all at once.
var myVariable = 10;
var total = myVariable * 50;
var total = 10 + 20;
var total = 10/20;
var total = 10 - 20;
var total = 10;
total++;
var total = 10;
total--;
if(x <= 10){}
if(myBoolean == true){
//this code would run if myBoolean evaluated to true
}
if(myBoolean != true){
//this code would run if myBoolean evaluated to false
//you could also do this...if(myBoolean == false){}
}
if(myBoolean){
//this code would run if myBoolean evaluated to true
}
if(!myBoolean){
//this code would run if myBoolean evaluated to false
}
if(myBoolean == true || x > 10){
//this code would run if myBoolean evaluated to true OR x is less than 10
}
if(myBoolean == true || x >= 10){
//this code would run if myBoolean evaluated to true OR x is less than OR equal to 10
}
if(myBoolean && x > 10){
//this code would run if myBoolean evaluated to true AND x is less than 10
}
if(myBoolean = true){
//Why don't we just you one equals sign?
}
var total = 10;
total += 5; //same as: total = total + 5
var total = 50;
total -= 25; //same as: total = total - 25
Use () to control the order of operations....
var myFirstName = "Niall";
var myLastName = "Kader";
var myAge = 38;
var myDogsAge = 5;