JavaScript Operators

Reagan MwangiReagan Mwangi
2 min read

Javascript provides a wide range of operators to perform various operations, from simple arithmetic to complex logical expressions. Here is an overview of the key categories of operators in JavaScript

1. Arithmetic Operators

  • Addition(‘+’): used to add two numbers or to concatenate strings.

  • subtraction(‘-’): used to subtract one number from another.

  • Multiplication(‘*’): used to multiply two numbers

  • Division(‘/’): used to divide one number with another

  • Reminder(‘%’): used to return the remainder from a division operation.

  • Exponentiation(‘**’): used to raise a number to a power.

2. Assignment Operators

Assignment operators are used to assign values to variables.

  • Simple Assessment(‘=’): used to assign a value to a variable.

  • Combined Assessment Operators: perform an arithmetic operation and then assign the result to a variable.

  • Add and Assign(‘+=’)

  • Subtraction and Assign(‘-=’)

  • Multiply and Assign(‘*=’)

  • Divide and Assign(‘/’)

  • Remainder and Assign(‘%=’)

  • Exponentiation and Assign(‘**=’)

3. Comparison Operators

Comparison operators are used to compare values and return a boolean(‘true’ or ‘false’)

  • Equality(‘==’) and strict Equality(‘===’):’==’ checks for equality with type conversion, while ‘===’ checks for equality without type conversion.

  • Inequality(‘!=’) and strict inequality(‘!===’)

  • Greater Than(‘>’) and Greater than or Equal To(‘>=’)

  • Less Than(‘<’) and Less than or Equal To(‘<=’)

4. Logical Operators

Logical operators are used to perform logical operations on boolean values

  • Logical AND(&&): returns true if both conditions are true

  • Logical OR(‘II’) returns true if one condition is true

  • Logical NOT(‘!’): returns the negation of a boolean value

5. Ternary Operators

The ternary operator is a shorthand for if-else statements.

6. Other Operators

  • Comma Operator(‘,’): Evaluates multiple expressions and returns the last one.

  • Typeof Operator(‘typeof’) returns the type of valuable

  • Instanceof Operator(‘instanceof’): checks if an object is an instance of a specific class or constructor.

These are the primary operators in JavaScript.Understanding their functionality and how to use them effectively is essential for writing effective and efficient JavaScript code.

10
Subscribe to my newsletter

Read articles from Reagan Mwangi directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Reagan Mwangi
Reagan Mwangi