Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #39181
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Writing type conversions |
| Date | 2020-11-24 09:56 +0100 |
| Message-ID | <i2405fFkf3eU1@mid.individual.net> (permalink) |
| References | <type-style-20201123132025@ram.dialup.fu-berlin.de> <g50orfttg03lruckcm11jkj0anf2h01ern@4ax.com> |
John G Harris: > On 23 Nov 2020 12:29:27 GMT, ram@zedat.fu-berlin.de (Stefan Ram) > wrote: > > <snip> >> However, in the Java world many deemed »+ ""« to be bad >> style because it does not express the intent of the >> programmer to convert something to a string but would >> mystify the reader. I do not share this point of view, >> however, because I think the intent of »+ ""« is clear. > > "" + x + 1 > makes it more obvious. But this may lead to the wrong result. Example: x = "4"; y = + x + 2; Result: "6" x = "4"; y = "" + x + 2; Result: "42" In general: if it is important to get a value as number, you should always create a numeric value from it using Number() and never rely on the expression itself. -- Arno Welzel https://arnowelzel.de
Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread
Re: Writing type conversions John G Harris <niam@jghnorth.org.uk.invalid> - 2020-11-23 18:34 +0000
Re: Writing type conversions Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-11-23 20:11 +0000
Re: Writing type conversions Arno Welzel <usenet@arnowelzel.de> - 2020-11-24 09:49 +0100
Re: Writing type conversions Silvio <silvio@internet.com> - 2020-11-24 10:58 +0100
Re: Writing type conversions Arno Welzel <usenet@arnowelzel.de> - 2020-11-24 18:56 +0100
Re: Writing type conversions Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-11-24 11:48 +0000
Re: Writing type conversions John G Harris <niam@jghnorth.org.uk.invalid> - 2020-11-24 18:34 +0000
Re: Writing type conversions Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-11-24 21:56 +0000
Re: Writing type conversions John G Harris <niam@jghnorth.org.uk.invalid> - 2020-11-25 15:32 +0000
Re: Writing type conversions Julio Di Egidio <julio@diegidio.name> - 2020-11-25 10:29 -0800
Re: Writing type conversions Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-11-25 19:58 +0000
Re: Writing type conversions Julio Di Egidio <julio@diegidio.name> - 2020-11-26 16:47 -0800
Re: Writing type conversions Arno Welzel <usenet@arnowelzel.de> - 2020-11-24 09:56 +0100
csiph-web