top of page
Writer's picture_Romeyo Boy_

JavaScript : Assignment Operator



The next very logically named operator in a chain is...


assignment operator!


And as you might have guessed, we use these to assign values to variables in JavaScript.


JavaScript : Assignment Operator - Creative Bloke
JavaScript : Assignment Operator

Assignment operators assign special values to variables.

  • = Specifies a value for the variable.

  • += Assigns to the variable and adds the value.

  • -= Assigns a value to a variable and subtracts it.

  • *= assigns a value to the variable and does the multiplication.

  • /= Specifies the value and splits the variable.

  • %= Specifies and adds the modulus or modulus to the variable.

Operators

Meaning

Examples

Equivalent Statement

Results

=

Equal

x = 8

x = 8

8

+=

Plus Equal

​x += 2

x = x + 2

10

-=

Minus Equal

x -= 3

x = x - 3

5

*=

Multiplication Equal

x *= 2

x = x * 2

16

/=

Division Equal

x /= 2

x = x / 2

4

%=

Modulus Equal

x %= 3

x = x % 3

​2



<> कोड उदाहरण :

Conscious! - You can use multiple assignment operators in one line, such as x -= y += 9





5 views0 comments

Recent Posts

See All

Comments


bottom of page