Answers for "JavaScript Operators"

2

javascript operators

&&	logical and
||	logical or
!	logical not
Posted by: Guest on January-12-2021
1

javascript operators

=  assignment operator 
var x = 2


+  addition operator
2 + 3 = 5


-  subtraction operator
2 - 3 = -1


*  multiplicative operator
2 * 3 = 6


/  division operator
3 / 2 = 1.5


%  modulus operator
3 % 2 = 1


++  increment operator
var x = 2
x++
// x now equals 3 (x = x + 1 in literal notation)


--  decrement operator
var x = 3
x--
// x now equals 2 (x = x - 1 in literal notation)


+=  additive reassignment operator
var x = 2
x += 3
// x now equals 5 (x = x + 3 in literal notation)


-=  subtractive reassignment operator
var x = 3
x -= 2
// x now equals 1 (x = x - 2 in literal notation)


*=  multiplicative reassignment operator
var x = 3
x *= 2
// x now equals 6 (x = x * 2 in literal notation)


/=  division reassignment operator
x = 3
x /= 2
// x now equals 1.5 (x = x / 2 in literal notation)


%=  modulus reassignment operator
x = 3
x %= 2
// x now equals 1 (x = x % 2 in literal notation)


==  logical comparison operator
2 == 2 // Returns true
2 == "2" // Returns true
2 == 3 // Returns false


===  logical strict comparison operator
2 === 2 // Returns true
2 === "2" // Returns false
2 === 3 // Returns false


!=  logical not equal comparison operator
2 != 3 // Returns true
2 != 2 // Returns false
2 != "2" // Returns false


!==  logical not equal strict comparison operator
2 !== 3 // Returns true
2 !== 2 // Returns false
2 !== "2" // Returns true


<  logical less than comparison operator
2 < 3 // Returns true
3 < 2 // Returns false


>  logical greater than comparison operator
3 > 2 // Returns true
2 > 3 // Returns false
3 > 3 // Returns false


<=  logical less than or equal to comparison operator
2 <= 3 // Returns true
3 <= 3 // Returns true
3 <= 2 // Returns false


>= logical less than or equal to comparison operator
3 >= 2 // Returns true
3 >= 3 // Returns true
2 >= 3 // Returns false


|| logical or operator
x = 3
(x == 3 || x == 2) // Returns true
(x == 2 || x == 1) // Returns false


&& logical and operator
x = 2
y = 3
(x == 2 && y == 3) // Returns true
(x == 2 && y == 4) // Returns false
Posted by: Guest on July-29-2021
3

javascript function to add two numbers

<!--Add two integer numbers using JavaScript.-->
<html>
	<head>
		<title>Add two integer numbers using JavaScript.</title>
		<script type="text/javascript">
			function addTwoNumbers(textBox1, textBox2){
				var x=document.getElementById(textBox1).value;
				var y=document.getElementById(textBox2).value;
				var sum=0;
				sum=Number(x)+Number(y);
				alert("SUM is: " + sum);
			}
		</script>
	</head>
<body>
	<h1>Add two integer numbers using JavaScript.</h1>
	<b>Enter first Number: </b><br>
	<input type="text" id="textIn1"/><br>
	<b>Enter second Number: </b><br>
	<input type="text" id="textIn2"/><br><br>
	<input type="button" id="btnSum" value="Calculate SUM" onClick="addTwoNumbers('textIn1','textIn2')"/>
</body>

</html>
Posted by: Guest on April-11-2020
6

or operator in javascript

//The OR operator in Javascript is 2 verticals lines: ||

var a = true;
var b = false;

if(a || b) {
	//one of them is true, code inside this block will be executed
}
Posted by: Guest on July-25-2020
3

javascript operators

==	equal to
===	equal value and equal type
!=	not equal
!==	not equal value or not equal type
>	greater than
<	less than
>=	greater than or equal to
<=	less than or equal to
?	ternary operator
Posted by: Guest on June-22-2021
0

JavaScript Operators

var x = 5;         // assign the value 5 to x
var y = 2;         // assign the value 2 to y
var z = x + y;     // assign the value 7 to z (5 + 2)
Posted by: Guest on November-27-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language