/    Sign up×
Community /Pin to ProfileBookmark

Possible to set conditional variable in 1 line

With the exception of the boolean variable, I’m wondering if it’s possible to combine the bottom 2 into one statement, so s exists in the current scope

[CODE]var boolean = (true or false)
var s;
boolean ? s = 40 : s = 80;[/CODE]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@cluefulJul 04.2011 — [CODE]var boolean = (true or false), s = boolean ? 40 : 80;[/CODE]
Copy linkTweet thisAlerts:
@Declan1991Jul 04.2011 — That's actually the point of the ternary operator pretty much, to allow you to do what clueful just did.
Copy linkTweet thisAlerts:
@Marius_MiliunasauthorJul 05.2011 — duh, i feel like an idiot for not thinking of that sooner. Thanks
×

Success!

Help @Marius_Miliunas spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...