473,555 Members | 2,333 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Truth in javascript

Hi everyone,

I'm a bit confused about some of the expressions used in conditional
statements.

One example:

for( i = 0; i < document.all.ta gs( elmID ).length; i++ )
{
obj = document.all.ta gs( elmID )[i];
if( !obj)
{
....
}
}

is this statement testing for the existence of the tags property? What
will the values stored in obj be if tags is/isn't supported? Will the
javascript continue to execute? (in my experience, FF shows an error
message in the javascript console saying that the property doesn't
exist).

The code above is included in an ' if(ie)' block, where 'ie =
document.all'. Having said that (and assuming that the initial code
listing is indeed testing the existence for the tags property), how can
the 'for' loop ever be entered if the tags property does exist (seeing
its used in the exit condition for the for loop)

Another unrelated question:

One line of code writes:

if (groupdiv.child ren[i].value =="undefined" )

Is this testing for the existence of the value property, or is it
testing to see if the value property is equal to 'undefined'.

Is this any different to writing:

if (groupdiv.child ren[i].value ==undefined)

(that is, without the speechmarks) - both statements appear in the same
body of code.

TIA for any help!

Taras

Jan 30 '06 #1
3 1412
"Taras_96" <ta******@gmail .com> writes:
I'm a bit confused about some of the expressions used in conditional
statements. .... obj = document.all.ta gs( elmID )[i];
(notice that "document.a ll" is part of the proprietary IE DOM, and
not a standard. Some browsers are likely to not support it.)
if( !obj) ....
is this statement testing for the existence of the tags property?
It checks that the value of the variable "obj" is not null (or, in
this case unlikely, one of the values: undefined, false, "", 0 or NaN).

I can't see why they do it, though.

They first make sure that "i" is in the range 0..length-1 of a
collection, and then pick out the i'th element of that collection.
It shouldn't be able to be null.
Will the javascript continue to execute? (in my experience, FF shows
an error message in the javascript console saying that the property
doesn't exist).
If you check the line number, it might be already at the first reference
to document.all.ta gs (recent Firefoxen have supported document.all, I
don't know whether they support document.all.ta gs).
The code above is included in an ' if(ie)' block, where 'ie =
document.all'.
That would disqualify Firefox. Their document.all object is a host
object that converts to a false value in a boolean context, exactly
to avoid being detected as IE.
One line of code writes:

if (groupdiv.child ren[i].value =="undefined" )

Is this testing for the existence of the value property, or is it
testing to see if the value property is equal to 'undefined'.
It's testing that the value property exists and is equal to the string
"undefined" . Even after type conversion, the value undefined will not
be equal to that string.
Is this any different to writing:

if (groupdiv.child ren[i].value ==undefined)
Yes.
Try executing
alert("undefine d"==undefine d);
(that is, without the speechmarks) - both statements appear in the same
body of code.


Ick.

What was meant might be:
if (typeof groupdiv.childr en[i].value == "undefined" )

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jan 30 '06 #2
Lasse Reichstein Nielsen wrote:
"Taras_96" <ta******@gmail .com> writes:
I'm a bit confused about some of the expressions used in conditional
statements.

...
obj = document.all.ta gs( elmID )[i];


(notice that "document.a ll" is part of the proprietary IE DOM, and
not a standard. Some browsers are likely to not support it.)


I think since IE-based browsers, Gecko-based browsers and Opera-based
browsers now featuring document.all, it is justified to say that there
are some browsers that do not support it and many browsers that are
likely not to support it _properly_, which is even worse. There are
widespread DOMs out there that (for whatever reason) do expose this
property but do not implement it as it is implemented in the IE DOM,
which is even more error-prone.
PointedEars
Jan 30 '06 #3
Cheers or the replies. It's been a hectic couple of weeks and I almost
forgot I had written this message!

Feb 9 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1624
by: lkrubner | last post by:
I've got a site on a hosted virtual server. I'd like to know the truth of what is going on, but I can't get past my browsers cache. There is some kind of error in my code that occurs on a given line. When I comment out that one line, everything else seems to work. When I uncomment that one line, the browser simply shows what was last on...
4
1130
by: James Stroud | last post by:
Hello All, I'm curious, in py0 | (1 == 1) 1 pyFalse | (1 == 1) True What is the logic of the former expression not evaluating to True (or
90
3387
by: John Salerno | last post by:
I'm a little confused. Why doesn't s evaluate to True in the first part, but it does in the second? Is the first statement something different? False print 'hi' hi Thanks.
2
1437
by: lemnitzer | last post by:
TV report: all 15 British sailors confess to illegally entering Iranian Waters Here are the links: http://news.google.com/news?hl=en&ned=us&q=all+15&btnG=Search+News http://www.canada.com/ottawacitizen/news/story.html?id=64454ab9-229c-44a8-9875-2f59e570c5f9&k=44029 NOW COMPARE THAT WITH THE YANK MOTHER FUCKING PEDOPHILE BASTARDS AND...
6
17097
by: natkw1 | last post by:
Hi all, I'm new to C and kind of confused on this. I've had a look around this group for suggestions but still not sure why the warning is occurring. What I've done is this <code snip> void foo(char loc) {
4
1404
by: laelahaellallah5 | last post by:
Explore & discover & be convinced that ISLAM is the truth! ... Please Visit: http://www.beconvinced.com
1
1619
by: Rohanrajs82 | last post by:
Hi, Can anybody help me? I have to construct a truth table of 97 columns. I have tester channels from 1 to 97. I have to make a truth table with all the possible combinations. Also, I have some dummy channels in it where I have to put a dummy value. Regards, Rohan.
6
11438
by: ambanks04 | last post by:
ok taking computer science class anybody know what to do i am not computer literate CoSc 111.003 Spring 2008 Assignment 4 1) Each student shall design, develop, code, test and submit an Original computer program which uses a function or functions to display the TRUTH TABLES for the Logical And, the Logical Or, and the Logical Not...
0
7622
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7547
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8060
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7904
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6176
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3596
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3575
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
865
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.