- meaning js code example
Example 1: javascript % meaning
// % is the modulo operator
// It returns the rest of a division
// Example uses:
27 % 5
// returns 2, as 27/2 is 5 with rest 2.
99 % 13
// returns 8, as 99/13 is 7 with rest 8.
420 % 0
// returns NaN, as division by 0 is not calculatable.
Example 2: what does -= mean in JavaScript
/* JavaScript shorthand -=
-= is shorthand to subtract something from a
variable and store the result as that same variable.
*/
// The standard syntax:
var myVar = 5;
console.log(myVar) // 5
var myVar = myVar - 3;
console.log(myVar) // 2
// The shorthand:
var myVar = 5;
console.log(myVar) // 5
var myVar -= 3;
console.log(myVar) // 2