It's important to grasp the distinction between the two assignment statements
var name = (equals) sets the value to whatever you want
var name = "blaqkippah"
console.log(name)
blaqkippah
var age = 23
console.log(age)
23
(since variable name has already been declared, there is no need to declare it again with the var keyword)
var name = "blaqkippah"
console.log(name)
blaqkippah
The use of += in conjunction with strings involves joining them together. It provides a more concise way of writing code
name = name + "blah"
name += "deemyBoy"
console.log(name)
blaqkippahdeemyBoy // no space inserted as I wrote += "deemyBoy" not += " deemyBoy"
ie. when joining 2 strings using += (or any other method) you have to manually add a
space
var b = 'banana'
b
"banana"
b += ' apple'
"banana apple"
b
"banana apple"
b = 'apple'
b
"apple"
Numbers behave differently with += acting as the plus/addition operator, adding to what's already stored in b
(with numbers you can also do -= (minus), *= (multiply) and /= (divide)
b = 2
console.log(b)
2
b += 3
console.log(b)
5
b = 4
console.log(b)
4
An example using minus:
b-=3
console.log(b)
1
An example using divide:
b /= 2
console.log(b)
0.5
An example using multiply:
b *= 50
console.log(b)
25
Returning to your question, I've utilized a JavaScript object so that innerHTML becomes a property on the object, allowing you to easily track the changing values in the console.logs
var btn = {} // declare empty JS object
undefined
btn.innerHTML = '<i class="fas fa-times fa-lg"></i>'; // assign value
console.log(btn)
{innerHTML: "<i class="fas fa-times fa-lg"></i>"}
btn.innerHTML += '<i class="fas fa-times fa-lg"></i>';
console.log(btn);
{innerHTML: "<i class="fas fa-times fa-lg"></i><i class="fas fa-times fa-lg"></i>"}
btn.innerHTML = '<i class="fas fa-times fa-lg">go back to original</i>';
console.log(btn);
{innerHTML: "<i class="fas fa-times fa-lg">go back to original</i>"}
This should provide a more comprehensive explanation for you