2.2 Arithmetic Operators

2.2 Arithmetic Operators

2.2 Arithmetic Operators

These are just your typical math operators. Very important in any programming language. Know them well!

Arithmetic Operators

Adds two numeric operands.
Subtract right operand from left operand.
Multiply two numeric operands.
Divide left operand by right operand.
Modulus operator. Returns remainder of two operands.
Increment operator. Increase operand value by one.
Decrement operator. Decrease value by one.
let x = 5;
let y = 10;

x + y; //returns 15

y - x; //returns 5

x * y; //returns 50

y / x; //returns 2

x % 2; //returns 1

x++; //returns 6

x--; //returns 4

+ Operator performs concatenation operation when one of the operands is of string type.

The following example shows how + operator performs operation on operands of different data types.

let a = 5, b = "Hello ", c = "World!", d = 10;

a + b; // "5Hello "

b + c; // "Hello World!"

a + d; // 15

When concatenating a number with a string, it won't actually do math. Only when a number is added with another number will it do math.


You can add practice problems here if you want. Follow the format below.


Copyright © 2021 Code 4 Tomorrow. All rights reserved. The code in this course is licensed under the MIT License. If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact classes@code4tomorrow.org for inquiries.