JavaScript Operators such as Arithmetic Operators, Assignment Operators, Comparison Operators, String Operators and Logical Operators

 

JavaScript Operators:

            Javascript operators are used to perform different types of mathematical and logical computations.


Types of JavaScript Operators

There are different types of JavaScript operators:

  • Arithmetic Operators
  • Assignment Operators
  • Comparison Operators
  • String Operators
  • Logical Operators
  • Bitwise Operators
  • Ternary Operators
  • Type Operators

JavaScript Arithmetic Operators

Arithmetic Operators are used to perform arithmetic on numbers.

Eg:

let a = 3;
let x = (100 + 50) * a;


addition            +

subtraction        -

multiplication    *

Division             /

Modulus             %

Increment          ++

Decrement          --



JavaScript Assignment Operators

Assignment operators assign values to JavaScript variables.

The Addition Assignment Operator (+=) adds a value to a variable.

Eg: 

        let x = 10;

      x += 5;

JavaScript String Comparison

All the comparison operators above can also be used on strings:

Eg:
         let text1 = "A";
    let text2 = "B";
    let result = text1 < text2;

Here 'A' changed to number in  ASCII ( American Standard Code for Information Interchange).

so A is small and B is big.

JavaScript String Addition

The + can also be used to add (concatenate) strings:

Eg:

let text1 = "John";
let text2 = "Doe";
let text3 = text1 + " " + text2;

console.log(text3);

Output:
        John Doe


Adding Strings and Numbers

Adding two numbers, will return the sum, but adding a number and a string will return a string

Eg:
let x = 5 + 5;
let y = "5" + 5;
let z = "Hello" + 5;
console.log(z);

Output:
    Hello5


JavaScript Logical Operators

Logical operators are used to determine the logic between variables or values.

Given that x = 6 and y = 3, the table below explains the logical operators

OperatorDescriptionExample
&&and(x < 10 && y > 1) is true
||or(x == 5 || y == 5) is false
!not!(x == y) is true

Sponsered by:

"This Content Sponsored by Genreviews.Online

Genreviews.online is One of the Review Portal Site

Website Link: https://genreviews.online/

Sponsor Content: #genreviews.online, #genreviews, #productreviews, #bestreviews, #reviewportal"

Comments