Why is
0 == "" in JavaScript
Since "A" + 0 != "A" + ""
thank you.
Gap 7 1315
wrote on 21 mrt 2008 in comp.lang.javas cript:
Why is
0 == "" in JavaScript
because
var result = 0 == "";
is not the same as
var result = 0 === "";
==========
With:
var result = 0 == "";
both being near equivalent to false,
and
var result = false == false;
results in true.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress) ga*****@gmail.c om wrote:
Why is
0 == "" in JavaScript
Since "A" + 0 != "A" + ""
Well, "A"+0 is "A0".
As for 0 == "", that's all done to automatic type conversions and the
fact that javascript considers false, 0, "", undefined all as false, and
the rest as true. So 0 is false and "" is false, therefore 0=="" ga*****@gmail.c om wrote:
Why is
0 == "" in JavaScript
Since "A" + 0 != "A" + ""
Mistakes were made.
Thomas 'PointedEars' Lahn wrote:
ga*****@gmail.c om wrote:
>Why is 0 == "" in JavaScript
Steps of evaluation (cf. ECMAScript Ed. 3 Final, sections 11.9.1 to 11.9.3):
0 == ""
+0 == +0
true
>Since "A" + 0 != "A" + ""
"A" + 0 != "A" + ""
!("A" + +0 == "A" + "")
!("A" + "0" == "A" + "")
!("A0" == "A")
!(false)
true
PointedEars
i think i see your answer to the OP is correct,
but how do you explain the apparent contradiction
0 == ""
AND
0 == "0"
?
Rick Merrill wrote:
Thomas 'PointedEars' Lahn wrote:
>ga*****@gmail.c om wrote:
>>Why is 0 == "" in JavaScript
Steps of evaluation (cf. ECMAScript Ed. 3 Final, sections 11.9.1 to 11.9.3):
0 == "" +0 == +0 true
>>Since "A" + 0 != "A" + ""
"A" + 0 != "A" + "" !("A" + +0 == "A" + "") !("A" + "0" == "A" + "") !("A0" == "A") !(false) true [...]
Please trim your quotes, do not quote signatures unless referring directly
to them.
i think i see your answer to the OP is correct,
but how do you explain the apparent contradiction
0 == ""
AND
0 == "0"
What is perceived as a contradiction by the OP and you here is ignoring that
string concatenation also involves type conversion.
PointedEars
--
var bugRiddenCrashP ronePieceOfJunk = (
navigator.userA gent.indexOf('M SIE 5') != -1
&& navigator.userA gent.indexOf('M ac') != -1
) // Plone, register_functi on.js:16
Rick Merrill <ri***********@ gmail.comwrites :
i think i see your answer to the OP is correct,
but how do you explain the apparent contradiction
0 == ""
AND
0 == "0"
That's not a contradiction, that's just type conversion.
See section 11.8.5 of the emacascript 262 specs:
The Abstract Equality Comparison Algorithm
The comparison x == y, where x and y are values, produces true or
false. Such a comparison is performed as follows:
1. If Type(x) is different from Type(y), go to step 14.
[ snip ]
14. If x is null and y is undefined, return true.
15. If x is undefined and y is null, return true.
16. If Type(x) is Number and Type(y) is String,
return the result of the comparison x == ToNumber(y).
^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^
[ snip ]
ToNumber("0") and ToNumber("") both evaluate to 0.
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Joost Diepenmaat wrote:
See section 11.8.5 of the emacascript 262 specs:
It is ECMA-262 or ECMAScript, not both. Otherwise you are correct.
PointedEars
--
var bugRiddenCrashP ronePieceOfJunk = (
navigator.userA gent.indexOf('M SIE 5') != -1
&& navigator.userA gent.indexOf('M ac') != -1
) // Plone, register_functi on.js:16 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Michael Stevens |
last post by:
Probably the wrong wording but since I'm not a scripter I won't claim
to know what I'm talking about.
I got this script from www.htmlgoodies.com
<script language="JavaScript">
<!--
window.open ('photos01.html','photogallery',config='height=550,
width=750,toolbar=no, menubar=no, scrollbars=no, resizable=no,
location=no, directories=no, status=no');
|
by: NecroJoe |
last post by:
I am using PHP to generate a little javascript for one of my pages. In
short it allows a user to select a value from a list and pop it into a form
field on a seperate page. This works well unless there is a " or ' in the
character string.
<SCRIPT language=JavaScript>
function Add_Term(SearchTerm) {
window.opener.document.advsearch.name_title.value +=
SearchTerm;
window.close();
|
by: David D. |
last post by:
Does the file extension matter when including a JavaScript file in an HTML
page?
Normally, one would include a JavaScript file in an HTML page using
<script src="foo.JS" type="text/javascript">
However, I have found that I can use an alternate file extension, such as
<script src="foo.HTML" type="text/javascript">
It works fine with my IE 6 and Mozilla. Will it work with other browsers?
|
by: Jon Davis |
last post by:
I recently learned how to do an <OBJECT> alternative to <IFRAME> in current
browsers using:
<object id="extendedhtml" type="text/html" data="otherpage.html" width="250"
height="400"></object>
My question is how do I access the document DOM of this object in
Javascript? For example, "alert(extendedhtml.innerHTML);" doesn't work and
produces an unknown error. I'd like to both read and write to the document's
body element's innerHTML...
|
by: Joeyej |
last post by:
Hi -
I'm trying to move/use a web form (containing some javascript field
checks) previously hosted on a Windows 2000 server. However, the FORM
METHOD="post..." command in the form (shown below) now renders "Page
not Found" when launched on the new Windows 2003 server (ws-server1).
The form is designed to use the write.asp program to write to an
Acccess database and is successful on any Windows 2000 server. This is
frustrating because...
| |
by: RFS666 |
last post by:
Hello,
I would like to use variables with a type in jscript.NET.
I declare them as follows:
var x : double = 5.03;
This doesn't work in my script, that I write to the page in codebehind with
"registerClientScriptBlock" as follows:
string script = "<script language=jscript>";
script += "function test()";
|
by: kelvlam |
last post by:
Hello,
I'm a new begininer with JavaScript. I'm trying to figure out which is
the best approach, and to understand the differences between them.
I have a <Aelement that's suppose to either launch a popup window, or
it will link you to some dynamic created page.
I have declared a global JavaScript function
|
by: jht5945 |
last post by:
For example I wrote a function:
function Func()
{
// do something
}
we can call it like:
var obj = new Func(); // call it as a constructor
or
var result = Func(); // call it as a function
|
by: Navodit |
last post by:
Hi
I am new to Javascript and am not sure what is the difference between the
following two statements:
<script type="text/javascript">
.....
</script>
|
by: dangt85 |
last post by:
Hello,
I have the following page:
...
<style type="text/css">
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
}
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |