Skip to main content
Practice

Operators

In programming, symbols like plus (+), minus (-), multiply (×), and divide (÷) are called operators.

Operators are used to process data (values) and generate new values.


Basic Operators

  1. Arithmetic Operators

These perform basic mathematical operations like in arithmetic.

  • + : addition

  • - : subtraction

  • * : multiplication

  • / : division

  • % : remainder

Multiplication Arithmetic Operator
let result = 5 * 3; // 5 x 3 = 15 is stored in result

  1. Comparison Operators

These compare the relationship between values or variables and return a true or false value.

  • == : equal (compares only values)

  • === : strict equal (compares values and types)

  • != : not equal

  • !== : strict not equal

  • > : greater than

  • < : less than

  • >= : greater than or equal to

  • <= : less than or equal to


Comparison Operator
let isTrue = 5 > 3; // true is stored in isTrue

  1. Logical Operators

These combine multiple conditions to determine a true or false value.

  • && : AND - true only if both conditions are true

  • || : OR - true if at least one condition is true

  • ! : NOT - inverts the truth value

AND Logical Operator
let value = true && false; // false is stored in value

  • Ternary Operator

A shorthand for conditional statements, it can be written as:

(condition) ? value1 : value2


Ternary Operator
let age = 15;
let type = age >= 20 ? 'adult' : 'teen'; // "teen" is stored in type

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.