Skip to content

Instantly share code, notes, and snippets.

@goodbedford
Last active April 2, 2016 14:07
Show Gist options
  • Select an option

  • Save goodbedford/8b9ebc25e2bf8cd2ba817260e685c027 to your computer and use it in GitHub Desktop.

Select an option

Save goodbedford/8b9ebc25e2bf8cd2ba817260e685c027 to your computer and use it in GitHub Desktop.
intro-js js-assignment-operators.js
// = the equal sign is the assignment operator;
var a = 10; // number ten is assigned to variable a;
var b = 20;
var c = 12;
a = c; // a is 12
console.log("a: " + a);
a = c = b; // a is 20, c is 20, b is 20
console.log("a: " + a);
// += the plus equal is the addition assignment operator
var a = 10;
console.log("a: " + a);
a += 1; // a is 11;
console.log("a: " + a);
a = a + 1; // a is 12
console.log("a: " + a);
// -= the minus equal is the subtraction assignment operator
a = 10;
console.log("a:" +a); // a is ten
a -= 1; //a is 9
console.log("a:" +a);
a = a - 1; //a is 8
console.log("a:" +a);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment