JavaScript Operators

Published by StudyMuch on

JavaScript Operators studymuch.in

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;

JavaScript Operators

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;

Compare Operator

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;

JavaScript Operators

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;

JavaScript Operators

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 –


13 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?

Cinderella Odham · January 16, 2023 at 9:12 am

I have recently started a site, the information you offer on this website has helped me tremendously. Thank you for all of your time & work.

how to be a payment service provider · December 12, 2023 at 11:12 am

I like what you guys are up too. Such intelligent work and reporting! Keep up the excellent works guys I have incorporated you guys to my blogroll. I think it will improve the value of my website 🙂

situs rajamas · January 18, 2024 at 3:13 pm

Excellent article. I am experiencing many of these issues as well..

Cruises · January 19, 2024 at 5:32 am

This is a very good tip especially to those new to the blogosphere. Simple but very accurate info… Thank you for sharing this one. A must read post.

Bryanwromb · January 23, 2024 at 9:51 am

Thanks for magnificent info. What trips can you recommend in 2024? Astro tourism, eco diving, home swapping, train stations are the new food destinations,sports tourism, coolcationing, gig tripping, private group travel?

Beauty Spa in Queens · February 11, 2024 at 3:04 am

Hi! This is my first visit to your blog! We are a collection of volunteers and starting a new initiative in a community in the same niche. Your blog provided us beneficial information to work on. You have done a wonderful job!

betting guest posts · February 24, 2024 at 1:31 pm

I enjoy reading a post that can make people think. Also, thanks for allowing for me to comment.

Piano cu · February 25, 2024 at 2:12 pm

I was extremely pleased to find this web site. I need to to thank you for your time just for this fantastic read!! I definitely appreciated every part of it and i also have you saved as a favorite to see new stuff on your web site.

film porno · April 9, 2024 at 1:14 pm

Wow that was strange. I just wrote an really long comment but after I clicked submit my comment didn’t show up. Grrrr… well I’m not writing all that over again. Anyway, just wanted to say superb blog!

bokep indo · April 9, 2024 at 2:27 pm

Right now it looks like WordPress is the preferred blogging platform available right now. (from what I’ve read) Is that what you are using on your blog?

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *