Google
 
Webnews.only-4-geeks.com
Interesting places
news.only-4-geeks.com Forum Index » JavaScript

FAQ Topic - Why does 1+1 equal 11? or How do I convert a str

 
Jump to:  
 
FAQ server
PostPosted: Mon Sep 01, 2008 9:00 pm    Post subject: FAQ Topic - Why does 1+1 equal 11? or How do I convert a str
       
-----------------------------------------------------------------------
FAQ Topic - Why does 1+1 equal 11? or How do I convert a
string to a number?
-----------------------------------------------------------------------

Javascript variables are loosely typed: the conversion between a
string and a number happens automatically. Since plus (+) is also
used as in string concatenation, ` '1' + 1 ` is equal to ` '11' `: the
String deciding what + does. To overcome this, first convert the
string to a number. For example: ` +varname ` or ` Number(varname) ` or
` parseInt(varname, 10) ` or ` parseFloat(varname) `.
Prompt and form control values are strings, as is the result from
a prompt window. Convert these to numbers before performing addition.

Additional Notes:

LINK

LINK


--
Postings such as this are automatically sent once a day. Their
goal is to answer repeated questions, and to offer the content to
the community for continuous evaluation/improvement. The complete
comp.lang.javascript FAQ is at LINK
The FAQ workers are a group of volunteers. The sendings of these
daily posts are proficiently hosted by LINK
 

Page 1 of 1 .:.

Google
 
Webnews.only-4-geeks.com

Windows Update | C++ | C | PHP | JavaScript | Photoshop | Programming | Windows 2000 | Python | Windows XP | Object | Flash | Flash - ActionScript | Paint Shop Pro | Excel | PowerPoint | Access | Word | Windows 98 | Internet Explorer 6.0 | CorelDraw12 | Java | XML | asm x86 | Linux Mandrake | Linux RedHat | Outlook |  | news from newsgroups |_ | s

Web Templates

Awesome Website Templates ©

przepisy kulinarne sztaplarki doładowanie Mieszkania Kraków katalog firm