Request a Free Demo

    Edit Template

    JavaScript Arithmetic Operators Explained with Examples

    JavaScript Arithmetic Operators Explained with Examples

    JavaScript Arithmetic Operators are essential for performing mathematical calculations in JavaScript programming. They help developers perform operations such as addition, subtraction, multiplication, division, and finding remainders.

    If you are learning JavaScript programming, understanding arithmetic operators is one of the most important steps toward building a strong programming foundation.

    In this JavaScript tutorial, we will explain all five arithmetic operators with practical JavaScript code examples, outputs, and step-by-step explanations.

    What Are Arithmetic Operators in JavaScript?

    Arithmetic operators are special symbols used to perform mathematical operations on numbers and variables.

    JavaScript provides five main arithmetic operators:

    OperatorNameDescription
    +AdditionAdds two values
    –SubtractionSubtracts one value from another
    *MultiplicationMultiplies two values
    /DivisionDivides one value by another
    %ModulusReturns the remainder

    Let’s understand each JavaScript arithmetic operator with practical examples.

    1. JavaScript Addition Operator (+)

    The addition operator (+) is used to add two numbers. In JavaScript, it can also combine two or more strings. This process is called string concatenation.

    Example 1: Addition of Two Numbers

    var a = 1;
    var b = 2;
    var c = a + b;
    
    console.log(c);

    Output:

    3

    Explanation:

    Here, variable a stores the value 1 and variable b stores the value 2. The addition operator adds both values and stores the result in variable c.

    Example 2: Addition of Two Strings

    var a = "hello";
    var b = "world";
    var c = a + b;
    
    console.log(c);

    Output:

    helloworld

    Explanation:

    When the addition operator is used with two strings, JavaScript combines both strings instead of performing mathematical addition. This is called string concatenation.

    Example 3: String + Number

    var a = "hello";
    var b = 1;
    var c = a + b;
    
    console.log(c);

    Output:

    hello1

    Explanation:

    Here, the first value is a string and the second value is a number. JavaScript converts the number into a string and combines both values.

    Example 4: Number + String

    var a = 1;
    var b = "hello";
    var c = a + b;
    
    console.log(c);

    Output:

    1hello

    Explanation:

    JavaScript converts the number 1 into a string and combines it with the string “hello”.

    Example 5: Multiple Values Using Addition

    console.log(1 + 2 + "3" + 4 + 5);

    Output:

    3345

    Explanation:

    JavaScript evaluates the expression from left to right.

    1. 1 + 2 = 3

    2. 3 + “3” = “33”

    3. “33” + 4 = “334”

    4. “334” + 5 = “3345”

    This example explains how JavaScript handles numbers and strings using the addition operator.

    2. JavaScript Subtraction Operator (-)

    The subtraction operator (-) is used to subtract one value from another.

    JavaScript automatically converts numeric strings into numbers during subtraction.

    Example 1: Subtraction of Two Numbers

    var a = 1;
    var b = 2;
    var c = a - b;
    
    console.log(c);

    Output:

    -1

    Explanation:

    The subtraction operation calculates 1 – 2. Therefore, the result is -1.

    Example 2: Number – String

    var a = 1;
    var b = "2";
    var c = a - b;
    
    console.log(c);

    Output:

    -1

    Explanation:

    JavaScript converts the numeric string “2” into the number 2 and performs the subtraction operation.

    Example 3: Number – Non-Numeric String

    var a = 1;
    var b = "hello";
    var c = a - b;
    
    console.log(c);

    Output:

    NaN

    Explanation:

    JavaScript cannot convert the string “hello” into a valid number. Therefore, the result is NaN.

    NaN stands for Not-a-Number.

    Example 4: Number – String with Comma

    var a = 1000;
    var b = "2,000";
    var c = a - b;
    
    console.log(c);

    Output:

    NaN

    Explanation:

    The string “2,000” contains a comma and cannot be directly converted into a valid number using JavaScript’s numeric conversion. Therefore, the subtraction operation returns NaN.

    3. JavaScript Multiplication Operator (*)

    The multiplication operator (*) is used to multiply two numbers or numeric values.

    JavaScript automatically converts numeric strings into numbers during multiplication.

    Example 1: Multiplication of Two Numbers

    var a = 1;
    var b = 2;
    var c = a * b;
    
    console.log(c);

    Output:

    2

    Explanation:

    The multiplication operation calculates 1 × 2. Therefore, the output is 2.

    Example 2: Number * String

    var a = 1;
    var b = "2";
    var c = a * b;
    
    console.log(c);

    Output:

    2

    Explanation:

    JavaScript converts the numeric string “2” into the number 2 and performs multiplication.

    Example 3: Number * Non-Numeric String

    var a = 1;
    var b = "hello";
    var c = a * b;
    
    console.log(c);

    Output:

    NaN

    Explanation:

    The string “hello” cannot be converted into a valid number. Therefore, JavaScript returns NaN.

    Example 4: Number * String with Comma

    var a = 1000;
    var b = "2,000";
    var c = a * b;
    
    console.log(c);

    Output:

    NaN

    Explanation:

    JavaScript cannot directly convert “2,000” into a valid numeric value because it contains a comma. Therefore, the multiplication operation returns NaN.

    4. JavaScript Division Operator (/)

    The division operator (/) is used to divide one number by another number.

    The result can be a whole number or a decimal value.

    Example 1: 4 / 2

    var a = 4;
    var b = 2;
    
    console.log(a / b);

    Output:

    2

    Explanation:

    4 divided by 2 equals 2.

    Example 2: 2 / 4

    var a = 2;
    var b = 4;
    
    console.log(a / b);

    Output:

    0.5

    Explanation:

    2 divided by 4 equals 0.5. JavaScript returns the decimal result.

    Example 3: 7 / 3

    var a = 7;
    var b = 3;
    
    console.log(a / b);

    Output:

    2.3333333333333335

    Explanation:

    When 7 is divided by 3, JavaScript returns a decimal result represented using floating-point arithmetic.

    5. JavaScript Modulus Operator (%)

    The modulus operator (%) returns the remainder after dividing one number by another number.

    It is useful when checking remainders and performing calculations such as identifying even and odd numbers.

    Example 1: 4 % 2

    var a = 4;
    var b = 2;
    
    console.log(a % b);

    Output:

    0

    Explanation:

    When 4 is divided by 2, the remainder is 0. Therefore, the modulus operator returns 0.

    Example 2: 7 % 3

    var a = 7;
    var b = 3;
    
    console.log(a % b);

    Output:

    1

    Explanation:

    When 7 is divided by 3, the quotient is 2 and the remainder is 1. Therefore, the output is 1.

    Difference Between Division (/) and Modulus (%)

    Both operators are used in mathematical calculations, but they return different results.

    Division (/)Modulus (%)
    Returns the division result.Returns the remainder.
    4 / 2 = 24 % 2 = 0
    2 / 4 = 0.52 % 4 = 2
    7 / 3 = 2.33333333333333357 % 3 = 1

    Remember:

    • Division (/) returns the quotient as a numeric result.

    • Modulus (%) returns the remainder after division.

    Practical Applications of JavaScript Arithmetic Operators

    JavaScript arithmetic operators are used in many real-world programming situations.

    Some common applications include:

    • Calculating student marks and percentages.

    • Calculating product prices and discounts.

    • Performing shopping cart calculations.

    • Calculating salaries and totals.

    • Finding even and odd numbers using modulus.

    • Performing calculations in web applications.

    Frequently Asked Questions (FAQs)

    1. What are arithmetic operators in JavaScript?

    Arithmetic operators are symbols used to perform mathematical operations such as addition, subtraction, multiplication, division, and modulus.

    2. How many main arithmetic operators are there in JavaScript?

    There are five main arithmetic operators: +, -, *, /, and %.

    3. What is the difference between + and – operators in JavaScript?

    The + operator performs addition or string concatenation, while the – operator performs subtraction and converts values to numbers when possible.

    4. What is NaN in JavaScript?

    NaN stands for Not-a-Number. It represents an invalid numeric result, such as subtracting a non-numeric string from a number.

    5. What is the difference between division and modulus?

    Division (/) returns the division result, whereas modulus (%) returns the remainder after division.

    6. Can JavaScript perform arithmetic operations on strings?

    Yes. JavaScript automatically converts numeric strings into numbers during subtraction, multiplication, and division. However, the addition operator may perform string concatenation.

    Learn JavaScript Programming at SSLABS

    Want to learn JavaScript and become a web developer?

    SSLABS offers practical programming training to help students build technical knowledge and develop real-world programming skills.

    Our Training Programs:

    Learn programming concepts through practical examples and real-time project training.

    Join SSLABS, Ameerpet, Hyderabad, and start your journey toward a successful IT career.

    Visit our website to explore our training programs and course details.

    Add these external links in the relevant paragraphs of the article.

    1. MDN JavaScript Guide – JavaScript learning documentation.

    2. MDN JavaScript Expressions and Operators – Official operator documentation.

    Watch JavaScript Arithmetic Operators Video Tutorial

    Learn JavaScript Arithmetic Operators through this practical video tutorial. Understand addition, subtraction, multiplication, division, and modulus with simple examples.

    Watch the complete video and practise the examples to improve your JavaScript programming skills.

    Previous Post
    Next Post

    Leave a Reply

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

    Empowering students with industry-relevant IT skills through practical training, real-time projects, and career-focused learning in Hyderabad.

    #402, Manjeera Plaza, Opp. Aditya Trade Centre, Ameerpet, Hyderabad – 500038

    Contact :9030006509

    © 2026 SSLABS