Javascript Operator Explained in Fewer than 5 minutes

Javascript Operator Explained in Fewer than 5 minutes

ยท

2 min read

Table of contents

No heading

No headings in the article.

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

ย