Type something to search...

JavaScript Operators

JavaScript Operators

Operators are used to perform operations on variables and values.

Types of Operators

  1. Arithmetic Operators: Perform mathematical operations.
    • + (Addition), - (Subtraction), * (Multiplication), / (Division), % (Modulus)
  2. Comparison Operators: Compare two values.
    • ==, ===, !=, !==, >, <, >=, <=
  3. Logical Operators: Combine multiple conditions.
    • && (AND), || (OR), ! (NOT)

Example

let a = 10, b = 20;
console.log(a + b); // Output: 30
console.log(a > b); // Output: false
console.log(a < b && b > 15); // Output: true

String Concatenation

You can use the + operator to concatenate strings:

let firstName = "John";
let lastName = "Doe";
let fullName = firstName + " " + lastName;
console.log(fullName); // Output: John Doe

Shorthand Operators

Shorthand operators simplify common operations:

let count = 5;
count += 2; // Equivalent to count = count + 2
console.log(count); // Output: 7

Next: Conditionals →