JavaScript Operators

Operators in JavaScript are symbols or keywords that perform operations on operands. Operands are values or variables that operators act upon. JavaScript supports various types of operators, which can be categorized based on their functionality.

In the below PDF we discuss about Javascript Operators in detail in simple language, Hope this will help in better understanding.


Types of JavaScript Operators:

1.  Arithmetic Operators:
JavaScript supports standard arithmetic operators such as addition (+), subtraction (-), multiplication (*), division (/), and modulus (%). These operators facilitate basic mathematical calculations within your code.

let a = 10;
let b = 3;
let sum = a + b; // 13
let difference = a - b; // 7
let product = a * b; // 30
let quotient = a / b; // 3.333...
let remainder = a % b; // 1

2. Assignment Operators:
Assignment operators are used to assign values to variables. The basic assignment operator is “=”, but JavaScript also offers shorthand versions like +=, -=, *=, and /=.

let x = 5;
x += 3; // equivalent to x = x + 3; // x is now 8

3. Comparison Operators:
These operators are crucial for making decisions in your code. They compare values and return a Boolean result.

let p = 5;
let q = '5';

console.log(p == q); // true (loose equality)
console.log(p === q); // false (strict equality)
console.log(p !== q); // true (strict inequality)

4. Logical Operators:
Logical operators are used to combine and manipulate Boolean values. The most common ones are AND (&&), OR (||), and NOT (!).

let sunny = true;
let warm = true;

if (sunny && warm) {
console.log('Perfect day!');

5. Unary Operators:
Unary operators work with a single operand. The most common unary operator is the negation operator (!).

let isRainy = false;
let isNotRainy = !isRainy; // true

6. Ternary Operator:
The ternary operator is a concise way to write an if-else statement in a single line.

let age = 20;
let status = (age >= 18) ? 'Adult' : 'Minor';

7. Bitwise Operators:
Bitwise operators manipulate the binary representation of numbers at the bit level. While they are not as commonly used, they can be powerful in specific scenarios.

let x = 5; // binary representation: 101
let y = 3; // binary representation: 011

let result = x & y; // bitwise AND: 001 (1 in decimal)

Related Question

In JavaScript, an operator is a symbol that performs an operation on one or more operands, producing a result.

JavaScript operators can be categorized into several types, including arithmetic, comparison, logical, assignment, bitwise, and more.

The addition operator in JavaScript is “+”. It is used to add two numbers or concatenate strings.

The modulo operator (%) returns the remainder of the division of one number by another. For example, 9 % 4 would result in 1.


Introduction to JavaScript JavaScript is

javaScript Statements In programming, a

Output in JavaScript JavaScript output

javaScript comments Comments in JavaScript

JavaScript Loops JavaScript loops are

JavaScript Performance and Debugging JavaScript

JavaScript Objects In JavaScript, objects

OOP in Javascript Object-Oriented Programming

JavaScript Functions Functions in JavaScript

Leave a Comment

Your email address will not be published. Required fields are marked *

// Sticky ads