Customer Login  .   Webmail Login  .   About Us  .   Contact Us
Go to: Articles List

How to use logical operators (||, &&, !)

Here is a some simple code to demonstrate the power and usefulness of the logical operators. If you are comparing several variables, like in form validation, it is helpful to use these. Change the values of the variables to see their effect.

|| = or
&& = and
! = not (!myvar returns false if myvar is true, returns true if myvar is false, in other words -- it makes it do the opposite of the normal if condition)

var1 = true
var2 = false
var3 = false
var4 = false

if ((var1 || var2) && (var3 || var4)) {
alert("got inside...");
} else alert("got ELSE...");

Shared Hosting
Rookie
Pro
Advanced
Dedicated Servers
BASE
BUSINESS
ENTERPRISE
Why Choose Brinkster?
Radical Support
Brinkster Datacenter
Brinkster Network
Corporate Social Responsibility
90 Day Money Back Guarantee
Unsurpassed Value
Client Testimonials
Additional Features
Antivirus
Merchant Account
E-Commerce
Live Chat Communicator
Free Firewall
Website Builder
Free Web Hosting
Support
General Support
Codebank Search
Forums
Articles
Click here for Brinkster Live Chat
Home   Domains   Shared Hosting   Dedicated Hosting   Partner   Support   About Us    Contact Us   Webmail
Copyright © Brinkster Communications Corporation All Rights Reserved. Privacy Policy & Legal