Learn JavaScript Operators






Javascript Operators simply perform operation and produce a result, there are various of operators, in this lesson we will learn about them and provide examples.



The addition operator (+)


Code Example:

                   
                   var a = 40;
var b = 10;
var c = a + b;
                 
                 
Try yourself >>




The multiplication operator (*)


Code Example:

                   
                   var a = 10;
var b = 5;
var c = a * b;
                 
                 
Try yourself >>




The assignment operator (=)


Code Example:

                   
                   var a = 5;         
var b = 10;         
var c = a + b;    // assign 5 and 10 to c (a + b)
                 
                 
Try yourself >>









Learn JavaScript Assignment Operators




Assignment operators are used to assign values to variables.


Operator Example Also equal to
+= x += y x = x + y
= x = y x = y
*= x *= y x = x * y
-= x -= y x = x - y
/= x /= y x = x / y
**= x **= y x = x ** y
%= x %= y x = x % y


The addition assignment operator (+=)


Code Example:

                   
                   var a = 10;
a += 5; //comment: we assign and add 5 to a(10), result: 15.
                 
                 
Try yourself >>


Visit our Javascript Assignment reference to learn the full guide of Assignment operators









JavaScript Arithmetic Operators


We use arithmetic operators to perform arithmetic on numbers:


Operator Description
* Multiplication
/ Division
+ Addition
- Subtraction
** Exponentiation (ES2016)
% Modulus (Division Remainder)
++ Increment
-- Decrement


Remainder (%)


Code Example:

                   
                   var a = 5;
var b = 2;
var c = a % b; // the modulus operator (%) returns the division remainder.
                 
                 
Try yourself >>


Visit our Javascript Arithmetic reference to learn the full guide of Arithmetic operators









JavaScript Comparison and Logical Operators


Comparison Description
== equal to
> greater than
< less than
=== equal value and equal type
!= not equal
!== not equal value or not equal type
? ternary operator
>= greater than or equal to
<= less than or equal to
Logical Operators Description
&& logical and
|| logical or
! logical not


greater than (>)


Code Example:

                   
                   jake = 10

                   if (jake > 20) {
                     jake = "Old enough";}

                     else {
                       jake = "Too young";
                     }
                 
                 
Try yourself >>


Visit our Javascript Comparisons reference to learn the full guide of Comparison operators









JavaScript Type Operators


Operator Description
typeof Returns the type of a variable
instanceof Returns true if an object is an instance of an object type


Visit our Javascript Type Conversion reference to learn the full guide of Type conversion








JavaScript String Operators


You can use the operators you have learned above with strings.


Code Example:

                   
                   var person1 = "Jake";
var person2 = "Sparrow";
var person3 = person1 + " " + person3;  
//comment: The result of person3 will be: Jake Sparrow
                 
                 
Try yourself >>











with FreeCodeWiki, you can learn Javascript and other Web development lessons for free, our main goal is to allow students to learn coding classes in one place for free.



Navigation