How to use Operators in JavaScript

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

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="">
<script type="text/JavaScript">
var linebreak = "<br />"
var my_var = "MCN IT SOLUTION"



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="">
<title>JavaScript logical AND operator</title>
<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..');
alert('beyond the limit.... ');


If we run this program and put value 45 then



If we enter 45 then



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


More Articles

© 2020 DotNetHeaven. All rights reserved.