Skip to main content

Command Palette

Search for a command to run...

Javascript Operator Explained in Fewer than 5 minutes

Published
2 min read
Javascript Operator Explained in Fewer than 5 minutes
D

🌍 African in Europe 💻 Designer & Developer 🤓 Always Learning 📱Apple Fanboy

In JavaScript, operators are used to perform operations on one or more values, such as arithmetic calculations, comparison, and logical operations.

  1. Arithmetic operators are used to perform mathematical operations like addition, subtraction, multiplication, division, and modulus

  2. Comparison operators are used to compare two values and return a boolean value based on the outcome of the comparison.

    For example, == checks for equality, > checks if the value on the left is greater than the value on the right, and <= checks if the value on the left is less than or equal to the value on the right

    .

  3. Logical operators are used to perform logical operations such as && (and), || (or), and ! (not). These operators return a boolean value based on the outcome of the operation

  4. Assignment operators are used to assign a value to a variable. The most basic assignment operator is =, which assigns the value on the right to the variable on the left. There are also shorthand assignment operators such as +=, -=, *=, and /= which can be used to add, subtract, multiply, or divide a value from a variable and then assign the result to the variable.

  1. Ternary operator is a shorthand way of writing an if-else statement, it takes 3 operands, a condition, a value if the condition is true, and a value if the condition is false. It has the following format: condition ? value if true : value if false

    Besides false, possible falsy expressions are: null, NaN, 0, the empty string (""), and undefined. If condition is any of these, the result of the conditional expression will be the result of executing the expression exprIfFalse.

  2. Other operators such as typeof, instanceof, and in operator are used to check the type or existence of a variable or property

    .

Each operator has different precedence and associativity, which affect the order in which the operations are performed.

Let me know your thoughts in the comments below!
Bye, for now! 👋 Diki

More from this blog

D

diki the dev

24 posts

Topics I write about: HTML, CSS & JavaScript As a designer I became frustrated not being able to code my own designs. This sparked the desire for me to dive into full stack JavaScript development.