What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Nudges, Updated.

2 votes - 2 average   Nudges, Updated.
Author: Message:
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Nudges, Updated.
[OFF TOPIC]

quote:
Originally posted by Plan-1130
Comparing the string 10 with the number 10 will result in NaN...
No...

Comparing it using the Equality Operators (== or !=) or Relational Operators will result in a match.

Comparing it with the Identity Operator (=== or !==) will result in a non-match (thus not an NaN-error). You will only get the NaN-error in specific calculations.

PS: It is preferred to use the Identity Operator (===) as this notifies you of possible type casting problems. It is also faster because JScript doesn't need to convert all variables to the same type, which it otherwise will always do.

See JScript 5.6 Documentation.
quote:
The following describes how the different groups of operators behave depending on the types and values of expression1 and expression2:

Relational (<, >, <=, >=)

* Attempt to convert both expression1 and expression2 into numbers.
* If both expressions are strings, do a lexicographical string comparison.
* If either expression is NaN, return false.
* Negative zero equals Positive zero.
* Negative Infinity is less than everything including itself.
* Positive Infinity is greater than everything including itself.

Equality (==, !=)

* If the types of the two expressions are different, attempt to convert them to string, number, or Boolean.
* NaN is not equal to anything including itself.
* Negative zero equals positive zero.
* null equals both null and undefined.
* Values are considered equal if they are identical strings, numerically equivalent numbers, the same object, identical Boolean values, or (if different types) they can be coerced into one of these situations.
* Every other comparison is considered unequal.

Identity (===, !==)

These operators behave identically to the equality operators except no type conversion is done, and the types must be the same to be considered equal.


quote:
Originally posted by Plan-1130
Still I don't know how I got many of my scripts working, as VB provides a function to parse an integer from a string
JScript too: parseInt(numString, [radix]).

eg: var numTen = parseInt("10");

Also see "CookieRevised's reply to [I help them] VB2JS" for some different uses of that method.

And parseFloat(numString) is the equivalent of the Val() function used on a string in VB.

But also note that in many cases you don't need to use it at all especially because of JScript's automatical type conversion.

If you have a string (eg: "10") and you multiply this with the number 5, JScript will automatically convert the string "10" to number 10, you will not get an error!.

Compare this behaviour with Variants in Visual Basic.

That is why this method works (but also why you almost never need to do this either):
quote:
Originally posted by Eljay
Just do varName * 1 to convert it, maybe slightly dodgy but short and simple :P


quote:
Originally posted by markee
For me I just do th following and it works (though I'm probably going about it the wrong way)
code:
var String = "10";
var Number = new Number(String);
I couldn't think of any other way of making it a number.  I hope this helps (assuming what I did is correct).
It is a correct way, but a long and often useless way... See comments above.

note there is a slight difference between this variable 'var Number' and the variable 'var numTen' from above. 'var Number' is declared as an number _object_, while var numTen is a variable containing a number.

The Number object is rarely necessary and the only usefull purpose is to collect its properties into one object (eg: so you can make your own properties for a number object using protoype) and to allow numbers to be converted into strings via the toString method.


[/OFF TOPIC]

This post was edited on 11-21-2006 at 12:32 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
11-21-2006 12:12 AM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Nudges, Updated. - by EBFL on 10-28-2006 at 06:51 PM
RE: Nudges - by Felu on 10-28-2006 at 06:54 PM
RE: Nudges - by EBFL on 10-28-2006 at 07:00 PM
RE: Nudges - by Felu on 10-28-2006 at 07:19 PM
RE: Nudges - by EBFL on 10-28-2006 at 07:41 PM
RE: Nudges - by Zahid™ on 10-28-2006 at 07:45 PM
RE: Nudges - by EBFL on 10-28-2006 at 07:47 PM
RE: Nudges - by Felu on 10-28-2006 at 07:48 PM
RE: Nudges - by EBFL on 10-28-2006 at 07:57 PM
RE: Nudges - by Zahid™ on 10-28-2006 at 07:59 PM
RE: Nudges - by Joakin on 10-28-2006 at 08:02 PM
RE: Nudges - by felipEx on 10-29-2006 at 01:18 AM
RE: Nudges - by EBFL on 10-29-2006 at 02:32 PM
RE: Nudges - by Felu on 10-29-2006 at 02:36 PM
RE: Nudges - by EBFL on 10-29-2006 at 02:40 PM
RE: Nudges - by Felu on 10-29-2006 at 03:00 PM
RE: Nudges - by Spunky on 10-29-2006 at 03:07 PM
RE: Nudges, Updated. - by Plan-1130 on 10-29-2006 at 07:52 PM
RE: Nudges, Updated. - by Felu on 10-30-2006 at 03:19 AM
RE: Nudges, Updated. - by EBFL on 10-30-2006 at 11:49 AM
RE: RE: Nudges, Updated. - by Baggins on 10-31-2006 at 01:35 AM
RE: Nudges, Updated Again! - by Spunky on 10-31-2006 at 11:29 AM
RE: Nudges, Updated Again! - by Plan-1130 on 10-31-2006 at 12:52 PM
RE: Nudges, Updated Again! - by Plan-1130 on 11-01-2006 at 06:44 PM
RE: Nudges, Updated. - by EBFL on 11-09-2006 at 09:22 PM
RE: Nudges, Updated. - by Plan-1130 on 11-10-2006 at 01:59 PM
RE: Nudges, Updated. - by EBFL on 11-10-2006 at 04:02 PM
RE: Nudges, Updated. - by orlandopunk on 11-11-2006 at 09:38 PM
RE: Nudges, Updated. - by bigbob85 on 11-11-2006 at 09:44 PM
RE: Nudges, Updated. - by orlandopunk on 11-11-2006 at 09:53 PM
RE: Nudges, Updated. - by CookieRevised on 11-12-2006 at 01:18 AM
RE: Nudges, Updated. - by Plan-1130 on 11-13-2006 at 09:18 AM
RE: Nudges, Updated. - by markee on 11-13-2006 at 09:57 AM
RE: Nudges, Updated. - by Eljay on 11-13-2006 at 11:11 AM
RE: Nudges, Updated. - by CookieRevised on 11-21-2006 at 12:12 AM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On