www.webdeveloper.com
Results 1 to 4 of 4

Thread: Possible to set conditional variable in 1 line

Hybrid View

  1. #1
    Join Date
    Apr 2010
    Location
    Brooklyn NY
    Posts
    104

    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;

  2. #2
    Join Date
    Dec 2010
    Posts
    207
    Code:
    var boolean = (true or false), s = boolean ? 40 : 80;


    Q: I found this code...
    A: Then find its author.

  3. #3
    Join Date
    Aug 2007
    Posts
    3,767
    That's actually the point of the ternary operator pretty much, to allow you to do what clueful just did.
    Last edited by Declan1991; 07-04-2011 at 05:34 PM. Reason: Beaten to it.
    Great wit and madness are near allied, and fine a line their bounds divide.

  4. #4
    Join Date
    Apr 2010
    Location
    Brooklyn NY
    Posts
    104
    duh, i feel like an idiot for not thinking of that sooner. Thanks

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles