JS TutorialJavascript-HomeJavascript-IntroductionJavaScript-File-UseJavascript-Output-ExampleJavaScript CommentJavaScript VariableJavaScript OperatorJavaScript ConsoleJavaScript StringJavaScript string splitJavaScript string sliceJavascript trim whitespaceJavaScript string indexOf methodJavaScript string lastIndexOf methodJavaScript DateJavascript conditional statement
JavaScript Operator
Operator can be used to perform any operation like - Arithmetic operation , Assignment operation ,Logical operation , Bitwise operation
Example
Assignment operator ( = )are used to assign value to a variable
/***** This is index.html file ****/
<script>
var int =4; // Assignment operator
console.log(int);
</script>
Result
4
Example
Arithmetic operator used to perform arithmetic operation
Addition Operator ( + )
/*** This is index.html file ****/
<script>
var x = 8;
var y = 14;
var z = x+y;
console.log(z);
</script>
Result
22
Arithmetic Operator
Arithmetic Operator used to perform arithmetic operation
Operator Example Name
+ x+y Addition
- x-y Subtraction
* x*y Multiplication
/ x/y Division
** x**y Exponentiation( ES2016)
% x%y Modulus
++ x++ Increment
-- x-- Decrement
Example
Subtraction arithmetic operator
var x = 14;
var y = 2;
var z = x - y;
console.log(z);
Assignment Operator
Assignment operator use to assign value to a variable
Operator Example Detail
= x=y equal to
+= 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
**= 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
>>= x>>=y x=x>>y
Example
Assignment operator
var x = 5;
var y =4;
x+=y; // Assign operator
console.log(x);
Comparison Operator
Comparison operator used to compare value and it return true or false
Operator Example Description
== x==y equal to
!= x!=y not equal to
=== x===y strict equal
!== x!==y strict not equal
> x>y greater than
>= x>=y greater than equal
< x<y less than