Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Js Arithmetic in JavaScript

Js Arithmetic in JavaScript

? JavaScript Arithmetic Operations


Basic Arithmetic Operators

OperatorDescriptionExampleResult
+Addition5 + 38
-Subtraction10 - 46
*Multiplication6 * 742
/Division20 / 54
%Modulus (Remainder)10 % 31
**Exponentiation2 ** 38

Increment and Decrement

let x = 5;x++;  // x = 6 (post-increment)++x;  // x = 7 (pre-increment)x--;  // x = 6 (post-decrement)--x;  // x = 5 (pre-decrement)

Compound Assignment Operators

let x = 10;x += 5;   // x = x + 5 = 15x -= 3;   // x = x - 3 = 12x *= 2;   // x = x * 2 = 24x /= 4;   // x = x / 4 = 6x %= 5;   // x = x % 5 = 1

Important Notes

  • Division by zero returns Infinity or -Infinity in JavaScript, not an error.

  • Modulus operator works with integers and floats, returns the remainder.

  • + operator also concatenates strings:

console.log(5 + "5"); // "55"console.log("5" + 5); // "55"

Example

let a = 7;let b = 3;console.log(a + b);  // 10console.log(a - b);  // 4console.log(a * b);  // 21console.log(a / b);  // 2.3333...console.log(a % b);  // 1console.log(a ** b); // 343

Want me to cover Math object methods for more complex arithmetic, like rounding, random numbers, or trigonometry?

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql