Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,931 questions

51,867 answers

573 users

How to use assignment operators (+= -= *= /= %=) in JavaScript

1 Answer

0 votes
var x = 13;
var y = 5;

x += y; // same as: x = x + y

document.write(x + "<br />"); // 18

x = 13;
y = 5;

x -= y; // same as: x = x - y

document.write(x + "<br />"); // 8

x = 13;
y = 5;

x *= y; // same as: x = x * y

document.write(x + "<br />"); // 65

x = 13;
y = 5;

x /= y; // same as: x = x / y

document.write(x + "<br />"); // 2.6

x = 13;
y = 5;

x %= y; // same as: x = x % y

document.write(x + "<br />"); // 3
  
/*
run:

18
8
65
2.6
3   

*/

 



answered Apr 15, 2017 by avibootz

Related questions

1 answer 204 views
1 answer 168 views
1 answer 171 views
1 answer 217 views
1 answer 72 views
72 views asked Apr 25, 2023 by avibootz
...