Stupid Javascript question

Andrej Marjan amarjan-e+AXbWqSrlAAvxtiuMwx3w at public.gmane.org
Mon Feb 14 17:45:43 UTC 2005


Lance F. Squire wrote:

> How do I add two values?
>
> a=2;
>
> A*A=4 but A+A=22
>
> Been searching google to no avail...


What kind of values? Given the above example, the variable a (lowercase) 
contains a number, and a+a = 4, as you would expect.

If I were to read your mind, I would guess that you're trying to accept 
user input and add it together. Well clearly you can't add strings -- 
what the user inputs -- and expect a number to pop out magically.

Have a look at parseInt(). And find a copy of the Netscape javascript 
guide and reference, it's still the best introductory stuff written.

Javascript is weakly typed, like Perl. Devin's kludge takes advantage of 
this fact to get Javascript to coerce strings into numbers.

It's actually a nice little language if you get to know it (think scheme 
with infix notation, sans macros). But it's always hosted in browsers, 
which suck, and commonly used with the DOM api, which sucks 
indescribably. (DOM is so bad that one of its creators apologized for it 
in his blog. ;)

That and most javascript guides target people who think HTML is a 
complicated programming language.

See http://www.crockford.com/javascript/javascript.html . He also has 
links to the Netscape guides.
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list