What are the data type in javascript

In this article, we will talk about all the operators we can do in JavaScript

What are the data type in javascript

First of all, you have to know that the operators it's kind of symbols that perform specific actions on values. In addition, there are many types of operators but in this article, we will focus on four of them:

  1. Arithmetic Operators
  2. Comparison Operators
  3. Logical Operators
  4. Assignment Operators

1- Arithmetic Operators

operator Description
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus (division remainder)
++ Increment
-- Decrement

 

 

 

 

 

 

 

 

Example:

<html>
<body>
<p>1 + 9 = <span id="opA"></span></p>
<p>6 - 4 = <span id="opB"></span></p>
<p>2 * 4 = <span id="opC"></span></p>
<p>8 / 4 = <span id="opD"></span></p>
<p>4 % 2 = <span id="opE"></span></p>
<p>2++ = <span id="opF"></span></p>
<p>2-- = <span id="opG"></span></p>

   <script>

        var A = 1 + 9, //Addition
         B = 6 - 4,    //Subtraction
         C = 2 * 4,    //Multiplication
         D = 8 / 4,    //Division
         E = 4 % 2,   //Modulus (division remainder)
         F = 2++,     //Increment
         G = 2--;     //Decrement

        document.getElementById("opA").innerHTML = A;
        document.getElementById("opB").innerHTML = B;
        document.getElementById("opC").innerHTML = C;
        document.getElementById("opD").innerHTML = D;
        document.getElementById("opE").innerHTML = E;
        document.getElementById("opF").innerHTML = F;
        document.getElementById("opG").innerHTML = G;


    </script>
</body>
</html>

Output:

1 + 9 = 10

6 - 4 = 2

2 * 4 = 8

8 / 4 = 2

4 % 2 = 0

2++ = 3

2-- = 1

2- Comparison Operators

operator Description
== equal to
=== Identical (equal value and equal type)
!= Not equal to
!== Not Identical (not equal value or not equal type)
> Greater than
>= Greater than or equal to
< Less than
<= Less than or equal to

 

 

 

 

 

 

 

 

 

Example:

<html>
<body>
<p>1 == 2 Result is <span id="opA"></span></p>
<p>1 === 2 Result is <span id="opB"></span></p>
<p>1 != 2 Result is <span id="opC"></span></p>
<p>1 !== 2 Result is <span id="opD"></span></p>
<p>1 &gt;	 2 Result is <span id="opE"></span></p>
<p>1 &gt;	= 2 Result is <span id="opF"></span></p>
<p>1 &lt;	 2 Result is <span id="opG"></span></p>
<p>1 &lt;	= 2 Result is <span id="opH"></span></p>

   <script>

        var A = 1==2,
        B = 1===2,
        C = 1!=2,
        D = 1!==2,
        E = 1>2,
        F = 1>=2,
        G = 1<2,
        H = 1<=2;
        

        document.getElementById("opA").innerHTML = A;
        document.getElementById("opB").innerHTML = B;
        document.getElementById("opC").innerHTML = C;
        document.getElementById("opD").innerHTML = D;
        document.getElementById("opE").innerHTML = E;
        document.getElementById("opF").innerHTML = F;
        document.getElementById("opG").innerHTML = G;
        document.getElementById("opH").innerHTML = H;

    </script>
</body>
</html>

Output:

1 == 2 Result is false

1 === 2 Result is false

1 != 2 Result is true

1 !== 2 Result is true

1 > 2 Result is false

1 >= 2 Result is false

1 < 2 Result is true

1 <= 2 Result is true

3- Logical Operators

Operator Description
&& AND
| | OR
! NOT

 

 

 

 

 

Example:

<html>
<body>
<h2>Example that A=1 and B=9</h2>
<p>(A &lt; 1 &amp;	&amp; B &gt;2) Result is <span id="opA"></span></p>
<p>(A == 1 || B == 3) Result is <span id="opB"></span></p>
<p>!(A == B) Result is <span id="opC"></span></p>

   <script>

        var A = 1,
        B = 9;
	
        document.getElementById("opA").innerHTML = (A < 1 && B > 2);
        document.getElementById("opB").innerHTML = (A == 1 || B == 3);
        document.getElementById("opC").innerHTML = !(A == B);

    </script>
</body>
</html>

Output:

Example that A=1 and B=9

(A < 1 & & B >2) Result is false

(A == 1 || B == 3) Result is true

!(A == B) Result is true

4- Assignment Operators

Operator Description Example Same as
= Assign A = 1 A = 1
+= Add and assign B += 1 B = B + 1
-= Subtract and assign C -= 1 C = C -1
*= Multiply and assign D *= 1 D = D * 1
/= Divide and assign E /= 1 E = E / 1
%= Modulus and assign F %= 1 F = F % 1

 

 

 

 

 

 

 

 

And that's it, my dear.

Last modified