Results 1 to 4 of 4

Thread: Question about general js codes

  1. #1
    Join Date
    Feb 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Question about general js codes

    I'm new to the javascript progamming field and I used w3Schools to learn javascript. I do not remember seeing in the tutorials or any tutorial what the statement below means.
    Code:
    If (!myFunction())
    what does the "!" infront of a function in an "if" statement mean.

    also what does it mean in statements like:
    Code:
    if (document.title)
    or
    Code:
    if(!document.title)
    Thanks for the help =]

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It means "not."
    Code:
    var a = false;
    a; // false
    !a; // true
    Everything in Javascript has a boolean value. 0, null, undefined, and an empty string are false; anything else is true.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    That's right. W3schools covers the meaning of ! as part of this page:

    http://www.w3schools.com/js/js_operators.asp
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    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."};
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •