Introduction to Arithmetic and Logical Operations
Getting Started with Arithmetic Operations

Arithmetic operations are pretty straightforward in JavaScript, just as they are in math. We use + for addition, - for subtraction, * for multiplication, / for division, % for getting the remainder of the division, and finally, ** for power operator.

// These are just like your typical calculator operations!

// Addition
let sum = 10 + 5; // Result: 15

// Subtraction
let difference = 10 - 5; // Result: 5

// Multiplication
let product = 10 * 5; // Result: 50

// Division
let quotient = 10 / 4; // Result: 2.5

// Remainder
let remainder = 14 % 4; // Result: 2 (14 = 4 * 3 + 2)

// Power
let powerResult = 10**3; // Result: 1000

As you can see above, the operators are placed between the numbers to conduct the calculations.

Integer division in JavaScript
Discovering the Power of Logical Operations

While arithmetic operations revolve around numeric calculations, logical operations deal with conditions. They return a boolean value: true or false. JavaScript uses AND (&&), OR (||), and NOT (!) for logical operations.

// Let's see how we can apply them:

console.log(true && true);      // 'true' AND 'true' = true 
console.log(true && false);     // 'true' AND 'false' = false
console.log(true || false);     // 'true' OR 'false' = true
console.log(false || false);    // 'false' OR 'false' = false
console.log(!true);             // NOT 'true' = false
console.log(!false);            // NOT 'false' = true

Here, we used the actual boolean values — true and false — to illustrate the basic workings of logical operators. In real life, however, these true and false will likely be some expressions, e.g., (a > 3) && (a < 5).

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal