Essential JavaScript Operators and Control Flow

Arithmetic Opreators

Basic mathematical operations in JavaScript include addition (+), subtraction (-), multiplication (*), division (/), and modulus (%).

console.log(5 + 3 * 2 / 1); // 11
let value = 15;
console.log(value % 4); // 3 (remainder)
console.log('text' - 5); // NaN (invalid operation)

Assignment Operators

Used to assign values to variables with combined operations:

let x = 10;
x += 5; // x = x + 5
x *= 2; // x = x * 2
console.log(x); // 30

Increment/Decrement Operators

let counter = 0;
counter++; // postfix increment
++counter; // prefix increment
console.log(counter); // 2

Comparison Operators

Return boolean values based on comparisons:

console.log(5 > 3); // true
console.log('5' == 5); // true (type coercion)
console.log('5' === 5); // false (strict equality)

Logical Operators

Combine boolean values:

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

Conditional Statements

If-Else

let age = 18;
if (age >= 18) {
    console.log('Adult');
} else {
    console.log('Minor');
}

Ternary Operator

let isMember = true;
let fee = isMember ? '$5' : '$10';
console.log(fee);

Switch Statement

let day = 3;
switch(day) {
    case 1: console.log('Monday'); break;
    case 2: console.log('Tuesday'); break;
    default: console.log('Other day');
}

Loops

While Loop

let i = 0;
while (i < 5) {
    console.log(i);
    i++;
}

Loop Control

for (let j = 0; j < 10; j++) {
    if (j === 5) break; // exits loop
    if (j % 2 === 0) continue; // skips even numbers
    console.log(j);
}

Tags: javascript Operators Control Flow programming

Posted on Fri, 19 Jun 2026 17:11:28 +0000 by Zephyr_Pure