Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Mar 2005
    Posts
    195
    Thanks
    0
    Thanked 0 Times in 0 Posts

    object detection - document.getElementById

    What to use when, what is the difference??



    Code:
    if(typeof document.getElementById == 'undefined') { return; }

    Code:
    if(!document.getElementById) return;

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    there is no difference AFAIK. the latter is shorter and therefore uses less bandwidth.
    *keep it simple (TM)

  • #3
    Regular Coder
    Join Date
    May 2005
    Posts
    313
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The result is the same, but the difference is type coercion during evaluation due to loose typing.
    Thanks in advance!

  • #4
    Regular Coder
    Join Date
    Mar 2005
    Posts
    195
    Thanks
    0
    Thanked 0 Times in 0 Posts

    do explain ...

    both could be used for object detection ??

    Quote Originally Posted by enumerator
    The result is the same, but the difference is type coercion during evaluation due to loose typing.
    difference is type coercion??:

    eg [found an example -->]For example, the value 0.5 is coercible to the type "32 bit floating point number" but not to the type "32 bit signed integer".

    what is meant during evaluation - the javascript parser parsing the script??

    loose typing --> have an example ??
    Last edited by _com; 07-12-2005 at 09:03 PM.

  • #5
    Regular Coder
    Join Date
    May 2005
    Posts
    313
    Thanks
    0
    Thanked 0 Times in 0 Posts
    slow down

    Here's an explanation (under the heading Coercion):
    http://msdn.microsoft.com/library/en...condeclare.asp

    Yeah, both can be used: each is an expression which produces the same result of evaluation (true or false). Which one to use is just a matter of preference.
    Thanks in advance!


  •  

    Posting Permissions

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