How Does += (Plus Equal) Work

R: += (plus equals) and ++ (plus plus) equivalent from c++/c#/java, etc.?

No, it doesn't, see: R Language Definition: Operators

What is += in Javascript?

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.

Java plus equals or equals plus operator?

It's not the same.

x+=5 is equivalent to x=x+5.

x=+5 (or x=(+5)) is equivalent to x=5.

Plus equals operator error

use parseInt() function to each amount which is getting from prompt

amount = parseInt(prompt("Enter the amount you want to deposit: $"), 10);

DEMO



Related Topics



Leave a reply



Submit