parseInt() and CSS naming was Re: [thelist] javascript "won't" subtract

Danny Goodman dannyg at dannyg.com
Mon Mar 10 09:41:01 CST 2003


on 3/9/03 10:48 PM, thelist-request at lists.evolt.org wrote:

>> JavaScript isn't a typed language, so it will treat a number as a
>> number when needed and as a string when needed - so no need to use
>> parseInt() (that's not the problem but it's unneeded.
>
> I've found in some forms that this /is/ actually needed.

The internal mechanism that attempts to convert string values to number
values is successful most of the time. The only time it definitely needs
help is when a "stringed" number value is an operand in an addition
operation because the + operator is ambiguous: it could be numerical
addition or string concatenation, the latter taking precedence over the
former (thus, 3+"3" becomes "33", whereas 3*"3" becomes 9).

>
>> Also, I believe the same naming convention of not starting with a digit
>> applies to the id and name attributes in HTML
>
> I remember that convention as well -- however, the page validates as XHTML
> 1.0 transitional AND CSS-2 happy. I went back and looked through the specs
> and couldn't find anything on naming conventions.

For all identifiers I tend to use ECMAScript naming conventions, which are
even more restrictive than HTML conventions, thus allowing me to use those
names in any kind of script reference (string or otherwise) while satisfying
all other requirements. The only allowed non-alphanumeric symbols are
underscore and dollar sign ($), but the latter is generally reserved for
machine-generated identifiers and isn't specifically accepted in the HTML
spec. Also, start the identifier with a non-number (as also required by the
HTML spec). Simple rules that keep everybody happy.

Danny
http://www.dannyg.com




More information about the thelist mailing list