5 Example(s) of JavaScript Assignment operators


Description :

In this example, We will see = assignment operator, Here we have a variable x and we are assigning it value as 10 and printing that html, See the code snippet:


JavaScript Assignment operators Example - 1
<!DOCTYPE html>
<html>
<head>
   <title>Welcome to LearnKode - A code learning platform</title>
</head>
  <body>
      <h2>= Operator</h2>
      <p id="sample"></p>
      
     <script> 
        var x=10;
        document.getElementById("sample").innerHTML = x;
      </script>
  </body>
</html>

Output

Description :

Example of JavaScript += Operator: var x=10; x+=6 will result into 16. See the code snippet:


JavaScript Assignment operators Example - 2
<!DOCTYPE html>
<html>
   <head>
   <title>Welcome to LearnKode - A code learning platform</title>
   
   </head>
   <body>
       <h2>+= Operator</h2>
       <p id="sample"></p>
      
       <script> 
         var x=10;
         x+=6;
        document.getElementById("sample").innerHTML = x;
      </script>
    </body>
</html>

Output

Description :

Example of JavaScript -= Operator: var x=10; x-=6 will result into 4. See the code snippet:


JavaScript Assignment operators Example - 3
<!DOCTYPE html>
<html>
   <head>
        <title>Welcome to LearnKode - A code learning platform</title>
        
  </head>
   <body>
      <h2>-= Operator</h2>
      <p id="sample"></p>
     
      <script> 
      var x=10;
      x-=6;
      document.getElementById("sample").innerHTML = x;
      </script>
    </body>
</html>

Output

Description :

Example of JavaScript *= Operator: var x=10; x*=6 will result into 60. See the code snippet:


JavaScript Assignment operators Example - 4
<!DOCTYPE html>
<html>
<head>
   <title>Welcome to LearnKode - A code learning platform</title>
    
 </head>
 <body>
     <h2>*= Operator</h2>
      <p id="sample"></p>
      <script> 
         var x=10;
         x*=6;
         document.getElementById("sample").innerHTML = x;
      </script>
      </body>
</html>

Output

Description :

Example of JavaScript /= Operator: var x=10; x/=2 will result into 5. See the code snippet:


JavaScript Assignment operators Example - 5
<!DOCTYPE html>
<html>
   <head>
<title>Welcome to LearnKode - A code learning platform</title>
   
    </head>
   <body>
       <h2>/= Operator</h2>
      <p id="sample"></p>
      <script> 
      var x=10;
      x/=2;
        document.getElementById("sample").innerHTML = x;
      </script>
      </body>
</html>

Output