JavaScript Tutorial
Estimated reading: 4 minutes 8 views

๐Ÿ”ข JavaScript Operators & Expressions โ€“ Complete Guide for Beginners (2025)


๐Ÿงฒ Introduction โ€“ What Are Operators and Expressions?

In JavaScript, operators are special symbols used to perform operations on variables and values. An expression is any valid combination of literals, variables, and operators that returns a result.

๐ŸŽฏ In this guide, youโ€™ll learn:

  • Different types of operators in JavaScript
  • How expressions are evaluated
  • Operator precedence and associativity
  • Special operators like typeof, delete, and ...spread

๐Ÿ“˜ Topics Covered

๐Ÿงฉ Topic๐Ÿ” Description
JavaScript OperatorsOverview of all operator types
Assignment OperatorsAssigning values to variables
Arithmetic OperatorsPerforming math calculations
Comparison OperatorsComparing values
Logical OperatorsHandling logical conditions
Bitwise OperatorsBinary-level operations
Conditional OperatorsTernary decision-making
typeof OperatorChecking data types
Nullish Coalescing OperatorHandling null and undefined
Safe Assignment OperatorLogical assignment variants
Delete OperatorRemoving properties from objects
Comma OperatorEvaluating multiple expressions
Grouping OperatorControlling operation order
Yield OperatorPausing functions (Generators)
Spread OperatorExpanding arrays/objects
Exponentiation OperatorRaising to a power (**)
Operator PrecedenceOrder of operation execution

๐Ÿ› ๏ธ JavaScript Operators โ€“ What Are They?

Operators are used to perform operations on data values. Examples:

let x = 10 + 5; // '+' is an arithmetic operator

โœ… Operators return values and form expressions that drive logic and behavior in programs.


๐Ÿ“ JS Assignment Operators

Assignment operators assign values to variables:

OperatorExampleEquivalent
=a = bAssign value of b to a
+=a += ba = a + b
-=a -= ba = a - b
*=a *= ba = a * b
/=a /= ba = a / b
%=a %= ba = a % b

โž• JavaScript Arithmetic Operators

Used to perform basic math:

OperatorDescriptionExample
+Addition5 + 3 โ†’ 8
-Subtraction5 - 3 โ†’ 2
*Multiplication5 * 3 โ†’ 15
/Division6 / 2 โ†’ 3
%Modulus5 % 2 โ†’ 1
**Exponentiation2 ** 3 โ†’ 8
++Incrementx++
--Decrementx--

โš–๏ธ JavaScript Comparison Operators

Used in condition checking:

OperatorDescriptionExample
==Equal (loose)"5" == 5 โ†’ true
===Strict equal"5" === 5 โ†’ false
!=Not equal4 != 5 โ†’ true
!==Strict not equal"4" !== 4 โ†’ true
>Greater than
<Less than
>=Greater than or equal
<=Less than or equal

๐Ÿ”— JavaScript Logical Operators

Used to combine or negate boolean expressions:

OperatorDescriptionExample
&&Logical ANDtrue && false โ†’ false
``
!Logical NOT!true โ†’ false

๐Ÿงฎ JavaScript Bitwise Operators

Operate on binary representations:

OperatorDescription
&AND
``
^XOR
~NOT
<<Left shift
>>Right shift
>>>Zero-fill right shift

Example:

5 & 1 // 1 (binary: 0101 & 0001 = 0001)

โ“ JavaScript Conditional (Ternary) Operator

The only ternary operator in JS:

let status = age >= 18 ? "Adult" : "Minor";

๐Ÿง  Syntax: condition ? expr1 : expr2


๐Ÿ” JavaScript typeof Operator

Returns the type of a value:

typeof "hello" // "string"
typeof 42      // "number"
typeof null    // "object" (JS quirk)

๐Ÿ’ก Nullish Coalescing Operator (??)

Returns the right-hand value if the left is null or undefined:

let name = null ?? "Guest"; // "Guest"

โœ… Better than || when 0 or "" should be valid.


๐Ÿ›ก๏ธ Safe Assignment Operators

Logical assignment operators:

OperatorExampleDescription
`=`
&&=a &&= bAssign b if a is truthy
??=a ??= bAssign b if a is null/undefined

๐Ÿ—‘๏ธ JavaScript delete Operator

Removes object properties:

let obj = { name: "John" };
delete obj.name; // true

๐Ÿ“š JavaScript Comma Operator

Allows multiple expressions in a single statement:

let x = (1 + 2, 3 + 4); // x = 7

๐Ÿ“Œ Only the last expression’s value is returned.


๐Ÿงฎ JavaScript Grouping Operator

Used to control precedence using parentheses:

let result = (2 + 3) * 4; // 20

๐Ÿ”„ JavaScript yield Operator

Used with Generators to pause and resume functions:

function* gen() {
  yield 1;
  yield 2;
}

Call with .next() to move through values.


๐Ÿ“ฆ JavaScript Spread Operator (...)

Expands elements from arrays or objects:

let arr = [1, 2];
let newArr = [...arr, 3, 4]; // [1, 2, 3, 4]

let obj = { a: 1 };
let newObj = { ...obj, b: 2 }; // {a:1, b:2}

๐Ÿงจ JavaScript Exponentiation Operator (**)

Raises a number to a power:

let power = 2 ** 3; // 8

Same as: Math.pow(2, 3)


๐Ÿ“Š JavaScript Operator Precedence

Determines the order in which operators are evaluated.

OperatorPrecedence
()Highest
**Right to left
*, /, %Left to right
+, -Left to right
<, >, ==, ===Comparison
&&, `
=, +=, *=Assignment (lowest)

๐Ÿ“Œ Use parentheses () to make complex expressions predictable.


๐Ÿ“Œ Summary โ€“ Recap & Next Steps

JavaScript operators and expressions are the backbone of logical operations and value assignments in any program. Mastering them gives you control over logic, flow, and calculations.

๐Ÿ” Key Takeaways:

  • Use arithmetic and assignment operators for calculations
  • Use typeof, ??, delete, and spread operators wisely
  • Understand operator precedence to avoid logic errors

โš™๏ธ Real-World Relevance:
Operators power everything from form validation to conditionals and API response processing. Every JavaScript app uses them heavily.


โ“ FAQs

Q1: Whatโ€™s the difference between == and ===?

โœ… == performs type coercion, while === checks both value and type strictly.

Q2: When should I use ?? instead of ||?

โœ… Use ?? when 0, false, or "" should be treated as valid values (i.e., not falsy).

Q3: Can I delete a variable declared with let?

โŒ No. delete only works on object properties.

Q4: What does the yield keyword do?

โœ… It pauses a generator function and resumes it on demand using .next().

Q5: What is operator associativity?

โœ… It defines the direction of execution (left-to-right or right-to-left) when multiple operators have the same precedence.


Share Now :

Leave a Reply

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

Share

๐Ÿ”ข JavaScript Operators & Expressions

Or Copy Link

CONTENTS
Scroll to Top