Skip to content

Latest commit

 

History

History
44 lines (32 loc) · 1.07 KB

02_operators.md

File metadata and controls

44 lines (32 loc) · 1.07 KB

Operators

Arithmetic operators

Arithmetic operators perform mathematical operations. Examples include:

let a = 5 + 3;  // addition
let b = 10 - 4;  // subtraction
let c = 4 * 2;  // multiplication
let d = 10 / 3;  // division
let e = 10 % 3;  // modulus (remainder)

Comparison operators

Comparison operators compare values and return a boolean. Examples include:

let a = 5 > 3;  // greater than
let b = 10 <= 4;  // less than or equal to
let c = 4 === 4;  // equal to (strict equality)
let d = 10 !== 3;  // not equal to (strict inequality)

Logical operators

Logical operators are used to combine or negate conditions. Examples include:

let a = (5 > 3) && (10 < 4);  // logical AND
let b = (5 > 3) || (10 < 4);  // logical OR
let c = !(5 > 3);  // logical NOT

Ternary operator

The ternary operator provides a concise way to write conditional statements. Example:

let age = 17;
let message = (age >= 18) ? "You can vote" : "You cannot vote";
console.log(message);  // Output: "You cannot vote"