What is difference between addition assignment operator and plus operator with blank string?

operator java
c# operator
operator python
operator javascript
c# event
minus operator in c#
subtract operator in c#
operator c

I have a code as below:

var point = '';
point = '' + 12 + 34;
console.log(point); // output = 1234

The difference is grouping. This:

point += + 12 + 34;

is equivalent to:

//              v-----------v---- note grouping
point = point + ( + 12 + 34 );
//                ^--- unary

The indicated + is a unary + which doesn't do anything there since 12 is already a number. So we have:

point = point + ( 12 + 34 );

which is:

point = point + 46;

which, since point starts out being "", is "46" (a string).

JavaScript assignment operators, for standard operations, as shown in the following table. Home LanguagesWhat is difference between addition assignment operator and plus operator with blank string? What is difference between addition assignment operator and plus operator with blank string? comment

In the first case, this is what happens:

  1. '' + 12 --> '12' (notice that now we have a string, as opposed to a number)
  2. '12' + 34 --> '1234' Javascript automatically coerces the number 34 to the string '34' in order to evaluate the expression

Instead, this is what happens in the second case:

  1. +12 --> 12 unary operator applied to the number 12, nothing happens
  2. 12 + 34 --> 46 pretty standard sum
  3. '' + 46 --> '46' empty string summed to the number 46, which results in the string '46'

What does '+=' mean in C programming?, . It is essentially a shorthand notation for incrementing the variable on the left by an arbitrary value on the right. The following two lines of C code are identical, in terms of their effect on the variable z: z = z + y; // increment z by y. For information about the arithmetic + operator, see the Unary plus and minus operators and Addition operator + sections of the Arithmetic operators article. String concatenation. When one or both operands are of type string, the + operator concatenates the string representations of its operands (the string representation of null is an empty string):

Per Addition Assignment Operator...

Using this operator is exactly the same as specifying: result = result + expression.

Your expression is +12 + 34, which evaluates to the integer 46.

point = point + expression
point = point + (+12 + 34)
point = point + 46
point = ""    + 46
point = "46"

You may notice that in the final step, "" combined with 46 gave us a string "46". Again, per the aforementioned documentation...

The types of the two expressions determine the behavior of the += operator:

If                                                         Then
---                                                        ---
Both expressions are numeric or Boolean                    Add
Both expressions are strings                               Concatenate
One expression is numeric and the other is a string        Concatenate

This would be an example of the third case. One expression is numeric (46) and the other is a string (""), so these two values concatenate to "46".

What is the difference between = (Assignment) and == (Equal to , checks whether the two given operands are equal or not. If so, it returns true. Otherwise it returns false. The addition assignment operator adds the value of the right operand to a variable and assigns the result to the variable. The types of the two operands determine the behavior of the addition assignment operator. Addition or concatenation is possible. See the addition operator for more details.

The addition assignment operator `(+=)` adds a value to a variable.
`x += y` means  `x = x + y`
The `+=` assignment operator can also be used to add (concatenate) strings:

Example: 

    txt1 = "What a very ";
    txt1 += "nice day";

The result of txt1 will be:

    What a very nice day

On the other hand adding empty String `''` will make javascript to
confuse Addition & Concatenation.
Addition is about adding numbers.
Concatenation is about adding strings.



    var x = 10 + 5;          // the result in x is 15
    var x = 10 + "5";        // the result in x is "105"

What do these ( += , -= , *= , /= ) Operators Mean?, String concatenation; Delegate combination; Addition assignment operator +=; Operator For information about the arithmetic + operator, see the Unary plus and minus of its operands (the string representation of null is an empty string):. C# This post shows the assignment, arithmetic and unary operators available in Java. Assignment operator in Java It assigns the value on its right to the operand on its left.

+ and += operators, They are things like addition + , multiplication * , subtraction - , and so on. String concatenation and conversion is a special feature of the binary plus + . The unary plus or, in other words, the plus operator + applied to a Let's note that an assignment = is also an operator. Is there any difference? Yes  Basic Operators¶. An operator is a special symbol or phrase that you use to check, change, or combine values. For example, the addition operator (+) adds two numbers, as in let i = 1 + 2, and the logical AND operator (&&) combines two Boolean values, as in if enteredDoorCode && passedRetinaScan.

Operators, Not surprisingly, strings belong to the type str and integers belong to the type int. Assignment operators link a name, on the left hand side of the operator, with a value, Addition, subtraction, multiplication, and exponentiation all do what you expect, The difference between the left and right hand sides of the assignment​  Using an lvalue of volatile-qualified non-class type as left operand of built-in direct assignment operator is deprecated, unless the assignment expression appears in an unevaluated context or is a discarded-value expression.

2. Variables, expressions and statements, By adding an empty string to a number, you convert the number to its string Earlier, you used the equal sign (=) as an assignment operator to assign a value to a or comparison with two values (the value on each side of an operator is called an + lastName; JavaScript uses the same plus operator for arithmetic addition. In addition to the basic assignment operator, there are "combined operators" for all of the binary arithmetic, array union and string operators that allow you to use a value in an expression and then set its value to the result of that expression.

Comments
  • JavaScript has an arithmetic operator and a string operator that do entirely different things but use the same symbol (+). That's life.
  • More about the use of assignment operator as I understand it... ecma-international.org/ecma-262/6.0/…
  • @ÁlvaroGonzález - JavaScript has one addition operator, which varies its action (math vs. concatenation) depending on its operands, not two separate operators with the same glyph: tc39.github.io/ecma262/#sec-addition-operator-plus
  • Main reason is that JavaScript is pure crap :)
  • avoid making a code sample format to the text that are not a code. Use CTRL+K to make your code to be a code sample format.