Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > The "undefined" value

Reply
Thread Tools

The "undefined" value

 
 
Luke Matuszewski
Guest
Posts: n/a
 
      11-20-2005
Richard Cornford has wrote great part of what i expected.

PS to avoid errors in statemtens like alert(cool) we could use
alert(this.cool); /* and thus really using [[Get]] method of JavaScript
which returns undefined if cool is not in scope */

Best regards.
Luke.

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      11-20-2005

Richard Cornford wrote:

> So, if you specify LANGUAGE="JavaScript1.2" you may get two different
> sorts of language behaviour from the interpreter depending on which
> browser is used. This is a _bad_thing_.


Note <https://bugzilla.mozilla.org/show_bug.cgi?id=255895>, with Firefox
1.5 (already in the betas and release candidates) Mozilla has dropped
the change that <script language="JavaScript1.2"> used to trigger for
script evaluation.
Of course one more reason not to use <script language="JavaScript1.2">
in HTML documents these days.

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
John G Harris
Guest
Posts: n/a
 
      11-20-2005
In article <(E-Mail Removed) .com>, VK
<(E-Mail Removed)> writes

<snip>
>This situation was fully satisfying for everyone except some bored
>academical minds. These minds did not like the fact that there is
>something that has a string representation ("undefined") but is not
>represented per se.
>
>Thus they have introduced *undefined* value. The consequence they did
>not think about was that this value will be able by default participate
>in the comparison operations *and* in the assignment operations. This
>created the following definitely buggy situation:

<snip>

No. In old browsers, ECMA 262 v2, the complicated rules for == meant you
couldn't tell the difference between null and undefined (never assigned
to).

Newer browsers, as recorded in ECMA 262 v3, have === which does allow
you to tell the difference. If x has never been assigned to it must now
have something it is === to, and it can't be null so they invented a new
keyword, undefined, to be that something.

John
--
John Harris
 
Reply With Quote
 
Randy Webb
Guest
Posts: n/a
 
      11-20-2005
Richard Cornford said the following on 11/20/2005 9:19 AM:
> Randy Webb wrote:
> <snip>
>
>>Thomas is a decent Theorist. If you want to learn a lot of
>>theory then read Richard Cornford. He is the best Theorist
>>around here.

>
>
> You don't think that Lasse Reichstein Nielsen has a better claim on that
> title (for his ability to place the theory in a wider context than I
> can)?


Never really thought about that one. I do know that when it comes to the
specs, I have never seen him be wrong about what they say.

::Off to ponder Lasse being a Theorist::
<g>
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
 
Reply With Quote
 
Randy Webb
Guest
Posts: n/a
 
      11-20-2005
Lasse Reichstein Nielsen said the following on 11/20/2005 7:44 AM:
> Randy Webb <(E-Mail Removed)> writes:
>
>
>>No browser will ever be 100% ECMA Compliant. When I say 100% I mean
>>that it follows everything in ECMA, implements it according to ECMA,
>>and nothing more.

>
>
> Well, that would be a different interpretation of "ECMA 262 compliant"
> than it uses itself. ECMAScript is meant to be extended, both at the
> runtime environment level with host objects, and with extended syntax
> and semantics. Being compliant means following everthing in the standard,
> but there is no requirement of "nothing more".


Fair enough.

> That said, I doubt there will ever be a 100% compliant implementation
> anyway. There will probably always be some obscure corner case that
> is implemented slightly incorrectly when used on the first Thursday
> of a month. "The number of bugs in a program is constant over time."


Indeed

>
>>It will never happen. So, even if you know ECMA 100%, it still won't
>>be enough because you will still have to know how the browsers deal
>>with it. May as well learn the browser behavior and you are set.

>
>
> Indeed. Still, the major problem with scripting browsers is not the
> Javascript language, browsers are very close to ECMAScript compliance.
> It is the browser DOM, which differs widely.


100% Agreed.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
 
Reply With Quote
 
Lasse Reichstein Nielsen
Guest
Posts: n/a
 
      11-20-2005
"matty" <(E-Mail Removed)> writes:

> The original question was if those constructs were legit. Is it a
> "standard" to use the "Javascript1.2" construct or not.


It is "standard" in the sense that it *can* be used in a validating
HTML 4.01 Transitional document.
The behavior is *not* standardized, but left up to the clients that
uses it.
It was never recommended by the W3C. The "language" attribute was
deprecated already in the first version of HTML that included it.
It was only included for compatability with existing browsers and
pages.

The use of "JavaScript1.2" as the version is possibly the worst value
of the language attribute that one can use, since it specifies a
version of Javascript that differs from other versions on the *same*
syntax. If it matters for your page, then the page *will* break in
the browsers that only support one version of Javascript.

/L
--
Lasse Reichstein Nielsen - http://www.velocityreviews.com/forums/(E-Mail Removed)
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      11-21-2005
Luke Matuszewski wrote:

> Richard Cornford has wrote great part of what i expected.


What are you referring to?
<URL:http://jibbering.com/faq/faq_notes/pots1.html#ps1Post>

> PS to avoid errors in statemtens like alert(cool) we could use
> alert(this.cool); /* and thus really using [[Get]] method of
> JavaScript which returns undefined if cool is not in scope */


True. However, `this.cool' is not always the same as `cool':

var cool = 42;

function Foo()
{
alert([this.cool, cool])
}

Foo.prototype = {
Foo: Foo,
cool: 1337
};

Foo(); // 42,42
var foo = new Foo(); // 1337,42
foo.Foo(); // 1337,42


PointedEars
 
Reply With Quote
 
Dr John Stockton
Guest
Posts: n/a
 
      11-21-2005
JRS: In article <(E-Mail Removed) .com>
, dated Sun, 20 Nov 2005 08:30:00, seen in news:comp.lang.javascript,
Luke Matuszewski <(E-Mail Removed)> posted :

>( * so there is no programmical way to test if variable was defined but
>not assigned a value explicitly... but i assume there is no need to )


var U // DO NOT ASSIGN TO U
var X
var Z1 = X==U
X = "something"
var Z2 = X==U
X = U
var Z3 = X==U
alert([Z1, Z2, Z3])

gives true,false,true so that one can very nearly tell.

Consider

function Inc(Parameter, maybeAnother) { var R, U
R = Parameter
if (maybeAnother != U) R += maybeAnother
return R }

(modelled on something in another language) which indicates a possible
use of testing for undefined.

The introduction of undefined as a keyword meaning undefined was a
great mistake, no doubt originated by a person with inadequate
experience of linguistics -- it makes discussion of the subject
unnecessarily difficult. Something like undef would have been
better, or unbestimmt or something neologistic such as wotzat .

There's something for saying that a language should not have reserved
words; instead, it should have reserved not-words - for example,
funkshun rather than function .

Implementations of Algol often used one of [ ' " ] as string quote and
the other as reserved word quote; and I recall one where "begin" was
written !begin but could be written as !beg. instead - any
special word could be so abbreviated to the minimum needed to be
differentiated from others. It made various forms of processing,
including discussion, easier. part of the software would expand any
such abbreviations.

--
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.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
 
Reply With Quote
 
Lasse Reichstein Nielsen
Guest
Posts: n/a
 
      11-21-2005
"Luke Matuszewski" <(E-Mail Removed)> writes:

> ( * so there is no programmical way to test if variable was defined but
> not assigned a value explicitly... but i assume there is no need to )


There shouldn't be a way, because there is no difference between a
declared variable that has not been assigned to, and one that has been
assigned the undefined value.

When you declare a variable, you create a property on the variable
object (the global object if in global scope). Quoting section 12.2
of ECMA262 3rd ed.:
"Variables are initialised to undefined when created."


(Curiosity: variable properties are created with the property attribute
DontDelete, except when inside eval scope. The following alerts the
result "number, undefined":
(function() {
var x = 42;
eval("var y = 37;");
delete x;
delete y;
alert([typeof x, typeof y]);
})()
The wonders of reading ECMA262 ...

/L
--
Lasse Reichstein Nielsen - (E-Mail Removed)
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how this is calculated "BW Util has exceeded the threshold value of 60%,The present value is 62% -" philip007 Cisco 1 01-31-2006 03:09 PM
The value of MCSD: added value to a degree? uv2003 MCSD 4 06-23-2005 05:41 AM
DataView Find method - Error: Expecting 2 value(s) for the key being indexed, but received 3 value(s) Zenobia ASP .Net 2 06-23-2004 05:15 PM
RE: Textbox postback putting value,value =?Utf-8?B?QW5hY2hvc3RpYw==?= ASP .Net 1 06-21-2004 10:50 AM
copying value of DDL in a Datagrid "pre-edit command" to value in "post edit command" San Diego Guy ASP .Net 0 08-07-2003 08:59 PM



Advertisments