PDA

View Full Version : Question about general js codes



xubera
02-25-2007, 10:01 AM
I'm new to the javascript progamming field and I used w3Schools (http://www.w3schools.com) to learn javascript. I do not remember seeing in the tutorials or any tutorial what the statement below means.

If (!myFunction())

what does the "!" infront of a function in an "if" statement mean.

also what does it mean in statements like:

if (document.title)
or

if(!document.title)

Thanks for the help =]

Twey
02-25-2007, 11:06 AM
It means "not."
var a = false;
a; // false
!a; // trueEverything in Javascript has a boolean value. 0, null, undefined, and an empty string are false; anything else is true.

jscheuer1
02-25-2007, 05:06 PM
That's right. W3schools covers the meaning of ! as part of this page:

http://www.w3schools.com/js/js_operators.asp

boxxertrumps
02-25-2007, 05:15 PM
exclamation points are also used in PHP to denote the same things.
if ($sound != "meow") {echo "Wrong sound."];

or standalone:

if (!$sound) {echo "Variable not set."} else {echo "Variable set."};