Answers for "what does += mean in JavaScript"

3

what does += mean in JavaScript

/* JavaScript shorthand +=
+= is shorthand to add something to a
variable and store the result as that same variable.
*/

// The standard syntax:
var myVar = 2; 
console.log(myVar) // 2
var myVar = myVar + 3;
console.log(myVar) // 5

// The shorthand:
var myVar = 2;
console.log(myVar) // 2
var myVar += 3;
console.log(myVar) // 5

/* In JavaScript, += can also concatenate strings */

// The standard syntax:
var myName = "Hi, I'm" 
console.log(myName) // Hi, I'm
var myName = myName + " Joe."
console.log(myName) // Hi, I'm Joe.

// The shorthand:
var myName = "Hi, I'm" 
console.log(myName) // Hi, I'm
var myName += " Joe."
console.log(myName) // Hi, I'm Joe.
Posted by: Guest on February-18-2020
0

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
Posted by: Guest on February-18-2020

Code answers related to "what does += mean in JavaScript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language