Jump to content

Featured Replies

Posted

You are reading Part 3 of the 39-part series: JavaScript Skill Progression: The Path from Beginner to Extreme. [Level 1]

Introduction

Operators and expressions form the backbone of JavaScript, allowing developers to perform calculations, compare values, and control logic. JavaScript provides various types of operators, including arithmetic, comparison, logical, and assignment operators. Understanding how these work is essential for writing efficient and effective code.

Operators and expressions are vital components of JavaScript, allowing developers to perform calculations, make decisions, and control program flow. Mastering arithmetic, comparison, logical, and assignment operators will enable you to write more effective and efficient JavaScript code.

Arithmetic Operators

Arithmetic operators perform mathematical calculations on numeric values.

Operator

Description

Example

+

Addition

let sum = 5 + 3; // 8

-

Subtraction

let difference = 10 - 4; // 6

*

Multiplication

let product = 6 * 3; // 18

/

Division

let quotient = 12 / 4; // 3

%

Modulus (Remainder)

let remainder = 10 % 3; // 1

**

Exponentiation (ES6)

let power = 2 ** 3; // 8

++

Increment

let x = 5; x++; // x is now 6

--

Decrement

let y = 10; y--; // y is now 9

Comparison Operators

Comparison operators evaluate values and return true or false.

Operator

Description

Example

==

Equal to (loose comparison)

5 == "5" // true

===

Strictly equal to

5 === "5" // false

!=

Not equal to

10 != 5 // true

!==

Strictly not equal

10 !== "10" // true

>

Greater than

7 > 5 // true

<

Less than

3 < 8 // true

>=

Greater than or equal to

5 >= 5 // true

<=

Less than or equal to

4 <= 6 // true

Logical Operators

Logical operators allow complex logical expressions by combining multiple conditions.

Operator

Description

Example

&&

Logical AND

(5 > 3) && (10 > 8) // true

`

`

!

Logical NOT

!(5 > 3) // false

  • && returns true only if both conditions are true.

  • || returns true if at least one condition is true.

  • ! negates the result, converting true to false and vice versa.

Assignment Operators

Assignment operators assign values to variables and modify them in shorthand.

Operator

Description

Example

=

Assign

let a = 10;

+=

Add and assign

a += 5; // a = a + 5

-=

Subtract and assign

a -= 3; // a = a - 3

*=

Multiply and assign

a *= 2; // a = a * 2

/=

Divide and assign

a /= 2; // a = a / 2

%=

Modulus and assign

a %= 3; // a = a % 3

**=

Exponentiate and assign

a **= 2; // a = a ** 2

Expressions in JavaScript

Expressions are combinations of values, variables, and operators that JavaScript evaluates to produce a result.

Types of Expressions:

  1. Arithmetic Expressionslet result = (5 + 2) * 3; // 21

  2. String Expressionslet fullName = "John" + " " + "Doe"; // "John Doe"

  3. Logical Expressionslet isValid = (5 > 3) && (10 > 8); // true

  4. Assignment Expressionslet x = 10;

You are reading Part 3 of the 39-part series: JavaScript Skill Progression: The Path from Beginner to Extreme. [Level 1]

  • Views 33
  • Created
  • Last Reply

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Important Information

Terms of Use Privacy Policy Guidelines We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.