JavaScript Operators

JavaScript Operators
In this tutorial you will learn about the JavaScript Operators, types of operators and how to use this in JavaScript with programming examples. Here given you many programming examples for your better revision about Operators. Now start to learn Operators.
What are Operators?
An Operators is a symbol that are used to perform particular operations, that takes one or more arguments and operates on them to product a result. They can be used to assign the values, combine values, compare values, perform arithmetic and more.
There are different types of Operators are used in JavaScript, that are given below;
- Assignment Operators
- Arithmetic Operators
- String Operators
- Comparison Operators
Now, you learn one by one all the given Operators in detail, with programming examples for your better understanding.
Assignment Operators
The Assignment Operator is an Operator that are used to assign the value to a variable, it uses the Equal = symbol. Look below some programming.
Examples of Assignment Operator;
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> Â <title>JS Operator</title> </head> <body> Â <script> Â Â Â var a = 6; Â Â Â var b = 8; Â Â Â var sum = a+b; Â Â Â document.write(sum); Â </script> </body> </html> |
Above example we add the two number with using the help of + operator and assign the result.
The addition assignment operator adds the value of the right operand to the value of the variable. Given below the example.
Examples of Assignment Operator (+=);
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> Â <title>JS Operator</title> </head> <body> Â <script> Â Â var a = 6; Â Â var b = 8; Â Â a += b; Â document.write("Sum Result = "+a); Â </script> </body> </html> |
Output;
Â
Above you see the programming and output of assignment operator, where we saw how to assign the value.
Arithmetic Operator
The Arithmetic Operator are used to perform arithmetic operations like (addition, subtraction, multiplication, and division) between the values (operands).
Here are the symbols used for the Arithmetic Operator to obtained the result.
- Addition +
- Subtraction –
- Multiplication *
- Division /
Now, we see the programming examples of Arithmetic Operator, using all the symbols given.
Examples of Arithmetic Operator (Addition & Subtraction);
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> Â <title>JS Operator</title> </head> <body> Â <script> Â Â Â var a = 6; Â Â Â var b = 8; Â Â Â var sum = a+b; Â document.write("Sum Result = " + sum); Â </script> Â <br> Â <script> Â Â Â var x = 20; Â Â Â var y = 7; Â Â Â var subtract = x-y; Â Â Â document.write("Subtraction Result = " + subtract) Â </script> </body> </html> |
Output;
Above you can see the programming example, where we add and subtract between two number with using “Subtract –” and “Addition +” Operators.
Examples of Arithmetic Operator (Multiplication & Division);
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> Â <meta name="viewport" content="width=device-width, initial-scale=1.0"> Â <title>JS Operator</title> </head> <body> Â <script> Â Â Â var a = 4; Â Â Â var b = 5; Â Â Â var sum = a*b; document.write("Multiplication Result = " + sum); Â </script> Â <br> Â <script> Â Â Â var x = 15; Â Â Â var y = 3; Â Â Â var subtract = x/y; Â Â document.write("Division Result = " + subtract) Â </script> </body> </html> |
Output;
You can see above programming and output of Arithmetic operator (Multiplication and Division), where the operation is done with multiply and divide operator between two operands.
Comparison Operators
The Comparison Operator compare its operands and return a Boolean based on whether the comparison is True or False. Given below the example where we compare with Comparison Operator the equality of two number.
Example of Comparison Operator;
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0">  <title>JS Operator</title> </head> <body>  <script>    var a = 4;    var b = 5;    var compare = a==b  document.write("Compare Result = " + compare);  </script>  <br>  <script>    var x = 15;    var y = 15;    var compare = x==y;    document.write("Compare Result = " + compare)  </script> </body> </html> |
Output;
Above you can see the programming example and also output of program, where we compare two numbers using the Comparison Operator, and we saw the result is in True or False (Boolean).
String Operators
The String Operator are used to attach or add the two strings value, the addition operator + and the addition assignment += are the string operator. Given below some examples of String operators where we concatenate two or three string values.
Programming Examples of String Operator;
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> Â <title>JS Operator</title> </head> <body> Â <script> Â Â var fname = "Shubham"; Â Â var lname = "Verma"; Â Â var fullname = fname + lname; Â document.write("Full Name is; "+ fullname); Â </script> Â <br> Â <script> Â Â var fname = "Ramesh"; Â Â var lname = "Verma"; Â Â fname += lname; Â Â document.write("Full Name; "+fname) Â </script> </body> </html> |
Output;
Above you can see programming example an output of String Operator, where use + and += operator to concatenate two string values.
Example of String Operator, here we concatenate three string value with the help of String operator.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>JS Operator</title> </head> <body> Â <script> Â Â var a = "StudyMuch"; Â Â var b = "is the best"; Â Â var c = " Educational Website."; Â Â var sentence = a+b+c; Â document.write("Sentence;" +sentence); Â </script> </body> </html> |
Output;
You can see above programming example with output, where we attach the three string values in a Sentence with the help of addition operator.
So, in this tutorial you learned all the JavaScript Operators with definition and programming examples of all the operators given in tutorial. I hope you read this tutorial (chapter) better and learn something new about the JavaScript Operators.
Read Also –
3 Comments
Phyliss Habig · September 23, 2022 at 8:45 am
I like this website because so much useful stuff on here : D.
marizon ilogert · October 6, 2022 at 11:49 am
I enjoy what you guys are up too. This type of clever work and exposure! Keep up the superb works guys I’ve included you guys to my blogroll.
marizon ilogert · October 10, 2022 at 5:44 am
Thanks , I have recently been looking for information approximately this topic for a while and yours is the greatest I have discovered till now. However, what in regards to the bottom line? Are you sure concerning the supply?