By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,677 Members | 1,890 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,677 IT Pros & Developers. It's quick & easy.

typeof operator returns "unknown" instead of "undefined"

P: n/a

IE7 returns "unknown" instead of "undefined" when querying the type of
an unknown property of an object, for example

document.write(typeof window.missingproperty);

Has "unknown" been defined as a valid return value for the typeof
operator in a later version of ECMAScript or is this a JScript "feature"?

--
Klaus Johannes Rusch
Kl********@atmedia.net
http://www.atmedia.net/KlausRusch/
Jul 25 '06 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Klaus Johannes Rusch wrote:
>
IE7 returns "unknown" instead of "undefined" when querying the type of
an unknown property of an object, for example

document.write(typeof window.missingproperty);

Has "unknown" been defined as a valid return value for the typeof
operator in a later version of ECMAScript or is this a JScript "feature"?
No to ECMAScript, yes to JScript - Microsoft added it to version 8,
along with 'date'.
--
Rob
Jul 26 '06 #2

P: n/a
JRS: In article <4i************@individual.net>, dated Wed, 26 Jul 2006
00:06:37 remote, seen in news:comp.lang.javascript, Klaus Johannes Rusch
<Kl********@atmedia.netposted :
>
IE7 returns "unknown" instead of "undefined" when querying the type of
an unknown property of an object, for example

document.write(typeof window.missingproperty);

Has "unknown" been defined as a valid return value for the typeof
operator in a later version of ECMAScript or is this a JScript "feature"?
It is bad to set follow-up without a note in the body; "FU set"
suffices. FU overridden.

My pages use such as
if (typeof(Inc1T)=='undefined') alert('File include1.js top fault, RSVP!')
with Inc1T=0 being defined at the top of file include1.js.

If this rather stupid change is confirmed, are there any suggestions for
alternatives to the above statement - preferably no longer, unlike
if ((typeof Inc1T).charAt(0)=='u') alert('File include1.js top fault, RSVP!')
?

FU set.

Read the newsgroup FAQ.
--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 26 '06 #3

P: n/a
Dr John Stockton said the following on 7/26/2006 8:42 AM:
JRS: In article <4i************@individual.net>, dated Wed, 26 Jul 2006
00:06:37 remote, seen in news:comp.lang.javascript, Klaus Johannes Rusch
<Kl********@atmedia.netposted :
>IE7 returns "unknown" instead of "undefined" when querying the type of
an unknown property of an object, for example

document.write(typeof window.missingproperty);

Has "unknown" been defined as a valid return value for the typeof
operator in a later version of ECMAScript or is this a JScript "feature"?

It is bad to set follow-up without a note in the body; "FU set"
suffices. FU overridden.
You are starting to act like TL. It is not bad set it without a note, it
is bad to set it at all on the original post. If the OP can figure out
where to set follow-up to then they should only post there as follow-up
is generally set to the most appropriate group.
My pages use such as
if (typeof(Inc1T)=='undefined') alert('File include1.js top fault, RSVP!')
with Inc1T=0 being defined at the top of file include1.js.
Why typeof? Why not just if(Inc1T). Depending on how Inc1T is defined
though.
If this rather stupid change is confirmed,
It is not a "stupid change", it actually makes sense.

are there any suggestions for
alternatives to the above statement - preferably no longer, unlike
if ((typeof Inc1T).charAt(0)=='u') alert('File include1.js top fault, RSVP!')
if (Inc1T)

But, it depends on how "unknown" gets translated to a Boolean. Does it
type convert to true or false?
Read the newsgroup FAQ.
For what reason in this post should they read the FAQ? Or is that your
new template?
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Answer:It destroys the order of the conversation
Jul 26 '06 #4

P: n/a
Randy Webb wrote:
Dr John Stockton wrote:
>Johannes Rusch wrote:
>>IE7 returns "unknown" instead of "undefined" when querying
the type of an unknown property of an object, for example

document.write(typeof window.missingproperty);
<snip>
>If this rather stupid change is confirmed,

It is not a "stupid change", it actually makes sense.
<snip>

If true, that all non-provided properties of the global/window object in
IE would report "unknown" when tested with the - typeof - operator, then
it would be a monumentally stupid modification for Microsoft to make to
in IE 7. It would probably kill 10% of browser scripts at a stroke.
Indeed it is such a stupid thing for Microsoft to have done that it is
extremely unlikely that they have done this, and instead it is the case
that the OP is misinterpreting whatever evidence he thinks he has for
this.

Defined properties of ActiveX objects, and some parts of the IE browser
object model, sometimes do return 'unknown' from typeof, so some poorly
selected property names may well produce the illusion of the effect
described. However, I have tested the substantial web application that I
am currently working on in IE 7 and encountered no significant issues
with it, and I cannot believe that in 60,000 lines of code there are no
typeof tests for non-'undefined' of global properties (even if none
spring to mind at the moment).

Richard.
Jul 26 '06 #5

P: n/a

Richard Cornford wrote:
Randy Webb wrote:
Dr John Stockton wrote:
Johannes Rusch wrote:
IE7 returns "unknown" instead of "undefined" when querying
the type of an unknown property of an object, for example

document.write(typeof window.missingproperty);
<snip>
If this rather stupid change is confirmed,
It is not a "stupid change", it actually makes sense.
<snip>

If true, that all non-provided properties of the global/window object in
IE would report "unknown" when tested with the - typeof - operator, then
it would be a monumentally stupid modification for Microsoft to make to
in IE 7. It would probably kill 10% of browser scripts at a stroke.
Indeed it is such a stupid thing for Microsoft to have done that it is
extremely unlikely that they have done this, and instead it is the case
that the OP is misinterpreting whatever evidence he thinks he has for
this.
Here's what I found in the JScript 8 Reference on MSDN:

<URL: http://msdn2.microsoft.com/en-us/library/d70y8358.aspx
>

Unfortunately, I can't find where they define the 'unkown' type, their
summary of data types is here (it doesn't mention unkown, undefined,
null...)

<URL: http://msdn2.microsoft.com/en-us/library/hhw1f6w5.aspx >

Defined properties of ActiveX objects, and some parts of the IE browser
object model, sometimes do return 'unknown' from typeof, so some poorly
selected property names may well produce the illusion of the effect
described. However, I have tested the substantial web application that I
am currently working on in IE 7 and encountered no significant issues
with it, and I cannot believe that in 60,000 lines of code there are no
typeof tests for non-'undefined' of global properties (even if none
spring to mind at the moment).
It would be nice to know from MS themselves how 'unknown' should
behave.
--
Rob

Jul 26 '06 #6

P: n/a
RobG wrote:
<snip>
It would be nice to know from MS themselves how 'unknown' should
behave.
the resulting value is Undefined, and typeof undefined is 'undefined'
so either Microsoft have seriously crippled compatibility with ECMA <=
3rd Ed. (so cross-browser compatibility in general) or the symptoms
have been miss-reported/identified. I may have time to try this myself
on IE 7 this afternoon.

Richard.

Jul 27 '06 #7

P: n/a


Richard Cornford wrote:

If true, that all non-provided properties of the global/window object in
IE would report "unknown" when tested with the - typeof - operator, then
it would be a monumentally stupid modification for Microsoft to make to
in IE 7. It would probably kill 10% of browser scripts at a stroke.
Indeed it is such a stupid thing for Microsoft to have done that it is
extremely unlikely that they have done this, and instead it is the case
that the OP is misinterpreting whatever evidence he thinks he has for
this.

Defined properties of ActiveX objects, and some parts of the IE browser
object model, sometimes do return 'unknown' from typeof,
I have made a test case
<http://home.arcor.de/martin.honnen/javascript/typeofTest1.html>
and it shows no difference in terms of 'unknown' results for me between
IE 6 and IE 7 beta 3. Only testing typeof on a property/method of an
ActiveX object gives 'unknown' and that has been known (pun intended)
before IE 7.
And ECMAScript edition 3 (11.4.3 The typeof Operator) for host objects
and typeof says
"Object (host) Implementation-dependent"
so an implementation is allowed to yield something different than the
predefined values 'undefined', 'number', 'boolean', 'string', 'object',
and 'function' in this case.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 27 '06 #8

P: n/a
JRS: In article <44c75b61$0$23525$5a62ac22@per-qv1-newsreader-
01.iinet.net.au>, dated Wed, 26 Jul 2006 22:07:39 remote, seen in
news:comp.lang.javascript, RobG <rg***@iinet.net.auposted :
>Klaus Johannes Rusch wrote:
>>
IE7 returns "unknown" instead of "undefined" when querying the type of
an unknown property of an object, for example

document.write(typeof window.missingproperty);

Has "unknown" been defined as a valid return value for the typeof
operator in a later version of ECMAScript or is this a JScript "feature"?

No to ECMAScript, yes to JScript - Microsoft added it to version 8,
along with 'date'.

I wonder whether IE7 counts my Inc1T as being an unknown property of an
object, if the include file defining it is not found?
From the FAQ, I take it that the term JScript includes the scripting
language in Microsoft's Web browsers.

<FAQENTRYISTM that, in the FAQ, it would be useful to have an
indication of the differences between JScript and ECMA-232 3rd Edn -
probably as an example entry with a link to Notes or elsewhere.

JScript "unknown" and "date" might be a good example.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 27 '06 #9

P: n/a
JRS: In article <X_******************************@comcast.com>, dated
Wed, 26 Jul 2006 15:34:21 remote, seen in news:comp.lang.javascript,
Randy Webb <Hi************@aol.composted :
>Dr John Stockton said the following on 7/26/2006 8:42 AM:
>JRS: In article <4i************@individual.net>, dated Wed, 26 Jul 2006
00:06:37 remote, seen in news:comp.lang.javascript, Klaus Johannes Rusch
<Kl********@atmedia.netposted :
>>IE7 returns "unknown" instead of "undefined" when querying the type of
an unknown property of an object, for example

document.write(typeof window.missingproperty);

Has "unknown" been defined as a valid return value for the typeof
operator in a later version of ECMAScript or is this a JScript "feature"?
>My pages use such as
if (typeof(Inc1T)=='undefined') alert('File include1.js top fault, RSVP!')
with Inc1T=0 being defined at the top of file include1.js.

Why typeof? Why not just if(Inc1T). Depending on how Inc1T is defined
though.
Evidently you have once more incorrectly assumed understanding on your
own part. Depending on circumstances, either Inc1T is defined or it is
not defined; TINA. If it's defined, all is (so far) well; no alert is
required. Its value is not used.

If it is not defined, I want to give my own specific recognisable
warning; I don't want the general use-of-undefined warning since that
could occur for other reasons elsewhere in the code : remember, this is
a Web application, so messages can be read by those other than the
author.

>If this rather stupid change is confirmed,

It is not a "stupid change", it actually makes sense.
Had it been introduced at the birth of Javascript, using "unknown" would
have been slightly better than using "undefined"; but to make such a
change, when in ECMA-263 3rd Edn "undefined" is defined and "unknown"
does not appear, is either ludicrous or a malicious commercial move.
Changing the set of results possible from typeof is unnecessary; it is
sufficient to have a new feature getType which returns the fuller
detail.
--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 27 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.