How to use of JavaScript operators ?


  • JavaScript operators are used to assign values, compare values, perform arithmetic operations, and more.
  • Arithmetic operators are used to perform arithmetic operations between variables and/or values.
  • Assignment operators are used to assign values to JavaScript variables.
  • The + operator, and the += operator can also be used to concatenate (add) strings.
  • The conditional operator assigns a value to a variable based on a condition.
  • Logical operators are used to determine the logic between variables or values.
  • Bit operators work on 32 bits numbers. Any numeric operand in the operation is converted into a 32 bits.
  • The typeof operator returns the type of a variable, object, function or expression.


  • Codes:-

  • <!DOCTYPE html> 
  • <html> 
  •  
  • <head> 
  •  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  • </head> 
  •  
  • <body> 
  •  
  •  <h1>JavaScript Operators</h1> 
  •  <h2>a=10; b=20 z=40; x=60; y=40; w=16;</h2> 
  •  
  •  <input type="button" onclick="cal_opr();" value="Find Operator usage"> 
  •  
  •  <div id="d1"></div> 
  •  
  •  <script> 
  •   function cal_opr() 
  •   { 
  •    var a = 10; 
  •    var b = 20; 
  •    var z = 40; 
  •    var x = 60; 
  •    var y = 40; 
  •    var w = 16; 
  •  
  •    var c = (a + b); //c=30 
  •    var d = (b - a); //d=10 
  •    z++; //z=z+1 => z=41 
  •    x--; //x=x-1 => x=59 
  •    y += 3; //y=y+3 => y=43 
  •    w -= 5; //w=w-5 => w=11 
  •  
  •    var e = a * b; //e=200 
  •    var f = a / b; //f=0.5 
  •    var g = a % b; //g=10 
  •  
  •    var all_txt = ""; 
  •  
  •    all_txt = "<br>a+b : " + c; 
  •    all_txt = all_txt + "<br>b-a : " + d; 
  •    all_txt = all_txt + "<br>z++ (z=z+1): " + z; 
  •    all_txt = all_txt + "<br>x-- (x=x-1): " + x; 
  •  
  •    all_txt = all_txt + "<br>y+=3 (y=y+3): " + y; 
  •    all_txt = all_txt + "<br>w-=5 (w=w-5): " + w; 
  •  
  •    all_txt = all_txt + "<br>a*b : " + e; 
  •    all_txt = all_txt + "<br>a/b : " + f; 
  •    all_txt = all_txt + "<br>a%b : " + g; 
  •    document.getElementById("d1").innerHTML = all_txt; 
  •   } 
  •  </script> 
  •  
  • </body> 
  •  
  • </html>
  • How to use of JavaScript operators ? How to use of JavaScript operators ? Reviewed by Network security on June 01, 2019 Rating: 5

    No comments:

    Useful Information

    Powered by Blogger.