bugl
bugl
HomeLearnPatternsSearch
HomeLearnPatternsSearch

Loading lesson path

Learn/JavaScript/JavaScript Foundations
JavaScript•JavaScript Foundations

JavaScript Assignment

Concept visual

JavaScript Assignment

Pointer walk
two pointers
leftright102132436485116
left=0
right=6
1
3

Start at both ends

JavaScript Assignment Operators

Assignment operators assign values to JavaScript variables.

Formula

Given that x = 10 and y = 5, the table below explains the assignment operators:

Operator

Example

Same As

Result

=

Formula

x = y x = y x = 5

+=

Formula

x += y x = x + y x = 15

-=

Formula

x -= y x = x - y x = 5

*=

Formula

x *= y x = x * y x = 50

**=

Formula

x **= y x = x ** y x = 100000

/=

Formula

x /= y x = x / y x = 2

%=

Formula

x %= y x = x % y x = 0

Formula

x: 45 size.x = 45 x = 45

Logical Assignment Operators

Operator

Example

Result

&&=

Formula

true &&= 10 x = 10

||=

Formula

false ||= 10 x = 10

??=

Formula

null ??= 10 x = 10
The = Operator

The

Simple Assignment Operator assigns a simple value to a variable.

Simple Assignment Examples let x = 10;
let x = 10 + y;
The += Operator

The

Addition Assignment Operator adds a value to a variable.

Addition Assignment Examples let x = 10;
x += 5;
The -= Operator

The

Subtraction Assignment Operator subtracts a value from a variable.

Subtraction Assignment Example

let x = 10;
x -= 5;
The *= Operator

The

Multiplication Assignment Operator multiplies a variable.

Multiplication Assignment Example

let x = 10;
x *= 5;
The **= Operator

The

Exponentiation Assignment Operator raises a variable to the power of the operand.

Exponentiation Assignment Example

let x = 10;
x **= 5;
The /= Operator

The

Division Assignment Operator divides a variable.

Division Assignment Example

let x = 10;
x /= 5;
The %= Operator

The

Remainder Assignment Operator assigns a remainder to a variable.

Remainder Assignment Example

let x = 10;
x %= 5;

String Assignment

Two assignment operators can assign values to strings:

The

Simple Assignment Operator assigns a simple value to a string.

The

Addition Assignment Operator adds a value to a string.

Formula

The = Operator

Previous

JavaScript Comments

Next

The JavaScript Ternary Operator