Skip to content

Buzzingz

Unleashing the Power of Code

  • HTML
  • CSS
  • JavaScript
  • Toggle search form

JavaScript Arithmetic

Posted on April 2, 2023April 2, 2023 By shani No Comments on JavaScript Arithmetic

Arithmetic operations are some of the most basic operations that can be performed in programming. In JavaScript, we have several built-in operators for performing arithmetic operations such as addition, subtraction, multiplication, and division. In this article, we will cover the different arithmetic operators available in JavaScript and how they can be used in programming.

Basic Arithmetic Operators

The basic arithmetic operators in JavaScript are as follows:

  • + for addition
  • - for subtraction
  • * for multiplication
  • / for division

Here’s an example of using these operators to perform arithmetic operations:

let x = 10;
let y = 5;
let z = x + y; // Addition
let w = x - y; // Subtraction
let a = x * y; // Multiplication
let b = x / y; // Division

Modulus Operator

Another commonly used arithmetic operator in JavaScript is the modulus operator, represented by the % symbol. The modulus operator returns the remainder of a division operation.

Here’s an example of using the modulus operator:

let x = 10;
let y = 3;
let z = x % y; // Modulus

In this example, z will be equal to 1, because 10 divided by 3 gives a remainder of 1.

Increment and Decrement Operators

JavaScript also provides increment and decrement operators to add or subtract 1 from a variable.

The increment operator is represented by ++, and the decrement operator is represented by --. Here’s an example:

let x = 10;
x++; // x is now 11
x--; // x is now 10 again

These operators can be used either before or after the variable name, depending on whether you want to perform the operation before or after the variable is used in an expression.

Operator Precedence

When multiple arithmetic operators are used in a single expression, JavaScript follows a specific order of precedence to determine the order in which the operations should be performed. The order of precedence is as follows:

  1. Parentheses ()
  2. Increment and decrement operators ++ and --
  3. Multiplication and division operators * and /
  4. Modulus operator %
  5. Addition and subtraction operators + and -

Arithmetic operations are fundamental to programming and are used in countless applications. In JavaScript, we have several built-in arithmetic operators for performing these operations, including addition, subtraction, multiplication, division, modulus, and increment/decrement. By understanding these operators and how to use them, you can create powerful programs that perform complex calculations and manipulate data.

Javascript

Post navigation

Previous Post: JavaScript Const
Next Post: JavaScript Operators

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

JavaScript Tutorial

  • JavaScript Tutorial
  • JavaScript Where To
  • JavaScript Output
  • JavaScript Statements
  • JavaScript Syntax
  • JavaScript Comments
  • JavaScript Variables
  • JavaScript Let
  • JavaScript Const
  • JavaScript Operators
  • JavaScript Arithmetic
  • JavaScript Assignment
  • JavaScript Data Types
  • JavaScript Functions
  • JavaScript Objects
  • JavaScript Events
  • JavaScript Strings
  • JavaScript String Methods
  • JavaScript String Search
  • JavaScript Template Literals
  • JavaScript Numbers
  • JavaScript BigInt
  • JavaScript Number Methods
  • JavaScript Number Properties
  • JavaScript Arrays
  • JavaScript Array Methods
  • JavaScript Sorting Arrays
  • JavaScript Array Iteration
  • JavaScript Array Const
  • JavaScript Date Objects
  • JavaScript Date Formats
  • JavaScript Get Date Methods
  • JavaScript Set Date Methods
  • JavaScript Math Object
  • JavaScript Random
  • JavaScript Booleans
  • JavaScript Comparison and Logical Operators
  • JavaScript if, else, and else if
  • JavaScript Switch Statement
  • JavaScript For Loop
  • JavaScript For In
  • JavaScript For Of
  • JavaScript While Loop
  • JavaScript Break and Continue
  • JavaScript Iterables
  • JavaScript Sets
  • JavaScript Maps
  • JavaScript typeof
  • JavaScript Type Conversion
  • JavaScript Bitwise Operations
  • JavaScript Regular Expressions
  • JavaScript Operator Precedence
  • JavaScript Errors
  • JavaScript Scope
  • JavaScript Hoisting: Understanding the Basics
  • JavaScript Use Strict: The Importance of Strict Mode in JavaScript
  • The JavaScript this Keyword
  • JavaScript Arrow Function: A Concise and Comprehensive Guide
  • JavaScript Classes: Understanding the Basics
  • JavaScript Modules
  • JavaScript JSON
  • JavaScript Debugging
  • JavaScript Style Guide
  • JavaScript Best Practices
  • JavaScript Common Mistakes: How to Avoid Them
  • JavaScript Performance: Techniques for Improving Your Code
  • About Us
  • Contact Us
  • Privacy Policy
  • Terms & Conditions

Copyright © 2023 Buzzingz.

Powered by PressBook WordPress theme