Skip to main content

Operations

An operation in JavaScript refers to an action that is performed on one or more values (operands) to produce a new value. Operations can be of several types, including:

  1. Arithmetic operations
  2. Comparison operations
  3. Logical operations
  4. Assignment operations

Arithmetic Operations

Arithmetic operations: These include addition +, subtraction -, multiplication *, division /, and modulus % operations. javascript


let x = 5, y = 3;
let result = x + y; // result = 8

Comparison Operations

Comparison operations: These are used to compare two values and return a boolean value indicating whether the comparison is true or false. Examples include > (greater than), < (less than), >= (greater than or equal to), <= (less than or equal to), == (equal to), and != (not equal to).

let x = 5, y = 3;
let result = x > y; // result = true

Logical Operations

Logical operations: These operations return a boolean value based on the truthiness or falsiness of one or more values. Examples include && (and), || (or), and ! (not).


let x = 5, y = 3;
let result = x > y && y > 0; // result = true

Assignment Operations

Assignment operations: These operations assign a value to a variable. Examples include =, +=, -=, *=, /=, and %=.


let x = 5;
x += 3; // x = 8

Operations are an essential part of any programming language, as they allow you to perform calculations, make decisions based on the result of a calculation, and change the values of variables. By using operations, you can write code that can perform complex tasks and solve real-world problems.