For example, in the while loop:
while (i < 10) {
text += "The number is " + i;
i++;
}
What does it do? Thanks.
In JavaScript, an object consists of key-value pairs where keys are similar to indexes in an array and are unique. If one tries to add a duplicate key with a different value, then the previous value for that key is overwritten by the new value.
Duplicate elements can be found using two loops. The outer loop will iterate through the array from 0 to length of the array. The outer loop will select an element. The inner loop will be used to compare the selected element with the rest of the elements of the array.
A duplicate value is one in which all values in at least one row are identical to all of the values in another row. A comparison of duplicate values depends on the what appears in the cell—not the underlying value stored in the cell.
It is the addition assignment
operator (+=
) to add a value to a variable.
Depending of the current type of the defined value on a variable, it will read the current value add/concat another value into it and define on the same variable.
For a string
, you concat the current value with another value
let name = "User";
name += "Name"; // name = "UserName";
name += " is ok"; // name = "UserName is ok";
It is the same:
var name = "User";
name = name + "Name"; // name = "UserName";
name = name + " is ok"; // name = "UserName is ok";
For numbers, it will sum the value:
let n = 3;
n += 2; // n = 5
n += 3; // n = 8
In Javascript, we also have the following expressions:
-=
- Subtraction assignment;
/=
- Division assignment;
*=
- Multiplication assignment;
%=
- Modulus (Division Remainder) assignment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With