How to use Operators in JavaScript

In this article I have described about the assignment and logical operator used in JavaScript
  • 2125

JavaScript Operator - Assignment Operator

Assignment operators come on account when we have to assign a value to JavaScript variable.

Lets take an example

In this example we have assign value to a variable named as "my_var".

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<body>
<script type="text/JavaScript">
var linebreak = "<br />"
var my_var = "MCN IT SOLUTION"
document.write(my_var)
document.write(linebreak)
</script>
</body>
</head>
</html>

 

Output

when we run this program value assign to variable named as my_var


assngmnt optr.gif

JavaScript Operator - Logical Operator

Following is the table of logical operators

      Operator            Description    Example
&& is true if both a and b are true a&&b
|| is true if either a or b is true a||b
! is true if a is not true !a

Lets take an example Logical AND operator

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>JavaScript logical AND operator</title>
</head>
<body>
<script type="text/javascript">
x = prompt('Input a number(between 1 and 50) : ');
if (x >= 1 && x < 50)
alert('The number is between 1 and 50..');
else
alert('beyond the limit.... ');
</script>
</body>
</html>

 

OUTPUT
If we run this program and put value 45 then


logi1.jpg

 

If we enter 45 then

logic2.jpg

 

Further Readings

You may also want to read these related articles :

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2018 DotNetHeaven. All rights reserved.