Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #32499 > unrolled thread
| Started by | Gene Wirchenko <genew@telus.net> |
|---|---|
| First post | 2017-02-06 09:16 -0800 |
| Last post | 2017-02-06 23:35 +0100 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.javascript
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Values of statements Gene Wirchenko <genew@telus.net> - 2017-02-06 09:16 -0800
Re: Values of statements "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-06 23:35 +0100
| From | Gene Wirchenko <genew@telus.net> |
|---|---|
| Date | 2017-02-06 09:16 -0800 |
| Subject | Re: Values of statements |
| Message-ID | <6obh9ctgdokncr59hskac44e2p47k776tq@4ax.com> |
On 4 Feb 2017 23:48:27 GMT, ram@zedat.fu-berlin.de (Stefan Ram) wrote:
> In JavaScript, statements have values. For example, the
> if statement has a value and thus it is very similar to
> the ternary operator.
>
>const name = a =>
>{ "use strict";
> return eval
> ( "if( a === 0 )'Null'; else if( a === 1 )'Eins'; else 'Zwei';" ); }
>undefined
>
>name( 0 )
>"Null"
>
>name( 1 )
>"Eins"
>
>name( 2 )
>"Zwei"
>
> But can something like the above be written without »eval«?
> (I.e., can the value of an if statement be obtained without »eval«?)
Replace the return with:
if (a===0)
return 'Null';
else
if (a===1)
return 'Eins';
else
return 'Zwei';
Sincerely,
Gene Wirchenko
[toc] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2017-02-06 23:35 +0100 |
| Message-ID | <XnsA714F00C61BAAeejj99@194.109.6.166> |
| In reply to | #32499 |
Gene Wirchenko <genew@telus.net> wrote on 06 Feb 2017 in comp.lang.javascript: > Replace the return with: > > if (a===0) > return 'Null'; > else > if (a===1) > return 'Eins'; > else > return 'Zwei'; > If a can only be 0,1,2 try the better looking: return ['Null','Eins','Zwei'][a]; -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web