Added JavaScript syntax, corrected capitalization & sentence. (#23684)

* Added JavaScript syntax, corrected sentence.


Corrected / Added:

 The other assignment operators "are usually" shorthand "methods" for performing "standard" operations using the variable (indicated by x above) and value (indicated by y above) and then assigning the result to the variable itself.

Added:

 JavaScript syntax to "Examples" and "Variations" .

Corrected:

The operator table title by adding an "A" and a capital S to JavaScript.

* fix: escaped bitwise OR operator
This commit is contained in:
binarygalwalkin
2018-10-23 06:43:53 -07:00
committed by Aditya
parent e099d6486d
commit 98d125f5f5

View File

@ -8,38 +8,37 @@ Assignment operators, as the name suggests, assign (or re-assign) values to a va
## Syntax ## Syntax
`x = y;` | Description | Necessity `x = y;`| Description | Necessity
:---------:|:---------------------:|:---------: :---------:|:---------------------:|:---------:
`x` | Variable | Required `x` | Variable | Required
`=` | Assignment operator | Required `=` | Assignment operator | Required
`y` | Value to assign to variable | Required `y` | Value to assign to variable | Required
## Examples ## Examples
```javascript
let initialVar = 5; // Variable initialization requires the use of an assignment operator let initialVar = 5; // Variable initialization requires the use of an assignment operator
let newVar = 5; let newVar = 5;
newVar = 6; // Variable values can be modified using an assignment operator newVar = 6; // Variable values can be modified using an assignment operator
```
## Variations ## Variations
The other assignment operators are a shorthand for performing some operation using the variable (indicated by x above) and value (indicated by y above) and then assigning the result to the variable itself. The other assignment operators are usually shorthand methods for performing standard operations using the variable (indicated by x above) and value (indicated by y above) and then assigning the result to the variable itself.
For example, below is the syntax for the addition assignment operator: For example, below is the syntax for the addition assignment operator:
```javascript
x += y; x += y;
```
This is the same as applying the addition operator and reassigning the sum to the original variable (i.e., x), which can be expressed by the following code: This is the same as applying the addition operator and reassigning the sum to the original variable (i.e., x), which can be expressed by the following code:
```javascript
x = x + y; x = x + y;
```
To illustrate this using actual values, here is another example of using the addition assignment operator: To illustrate this using actual values, here is another example of using the addition assignment operator:
```javascript
let myVar = 5; // value of myVar: 5 let myVar = 5; // value of myVar: 5
myVar += 7; // value of myVar: 5 + 7 = 12 myVar += 7; // value of myVar: 5 + 7 = 12
```
## Complete list of Javascript's assignment operators ## A complete list of JavaScript's assignment operators
Operator | Syntax | Long version Operator | Syntax | Long version
------------------------------- | --------- | ------------- ------------------------------- | --------- | -------------
Assignment | x = y | x = y Assignment | x = y | x = y
@ -54,7 +53,7 @@ Right shift assignment | x >>= y | x = x >> y
Unsigned right shift assignment | x >>>= y | x = x >>> y Unsigned right shift assignment | x >>>= y | x = x >>> y
Bitwise AND assignment | x &= y | x = x & y Bitwise AND assignment | x &= y | x = x & y
Bitwise XOR assignment | x ^= y | x = x ^ y Bitwise XOR assignment | x ^= y | x = x ^ y
Bitwise OR assignment | x |= y | x = x | y Bitwise OR assignment | x \|= y | x = x \| y
### More Information: ### More Information: