Course

Arithmetic Operators

Loading...

In this lesson, you'll learn how to use in JavaScript to perform basic mathematical operations, including addition, subtraction, multiplication, division, modulus, increment, decrement, and exponentiation.

Arithmetic Operators

Arithmetic operators in JavaScript are essential for performing mathematical operations on numeric operands. These include basic operations like addition , multiplication , and subtraction , which are familiar from school. These operators are fundamental in programming for handling calculations and data manipulation.

Here's how you can use arithmetic operators in JavaScript:

// Arithmetic Operators Demo in JavaScript

// Addition (+)
const sum = 10 + 5; 
console.log("Addition: 10 + 5 =", sum); // Output: 15

// Subtraction (-)
const difference = 20 - 7; 
console.log("Subtraction: 20 - 7 =", difference); // Output: 13

// Multiplication (*)
const product = 6 * 4; 
console.log("Multiplication: 6 * 4 =", product); // Output: 24

// Division (/)
const quotient = 15 / 3; 
console.log("Division: 15 / 3 =", quotient); // Output: 5

// Modulus (%) - Remainder after division
const remainder = 17 % 5; 
console.log("Modulus: 17 % 5 =", remainder); // Output: 2

// Exponentiation (**)
const power = 3 ** 3; 
console.log("Exponentiation: 3 ** 3 =", power); // Output: 27

// Increment (++)
let incrementValue = 5;
incrementValue++; // Equivalent to incrementValue = incrementValue + 1
console.log("Increment: 5++ =", incrementValue); // Output: 6

// Decrement (--)
let decrementValue = 8;
decrementValue--; // Equivalent to decrementValue = decrementValue - 1
console.log("Decrement: 8-- =", decrementValue); // Output: 7

These operations are straightforward and form the backbone of many programming tasks. Understanding how to use them effectively is crucial for any JavaScript developer. Now that we've covered , let's move on to ! 😊

Loading...

0 Comments

"Please login to view comments"

glass-bbok

Join the Conversation!

Subscribing gives you access to the comments so you can share your ideas, ask questions, and connect with others.

Upgrade your account
tick-guideNext Lesson

Comparison Operators and Equality