Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3330602
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:30:26+00:00 2026-05-17T23:30:26+00:00

If you hate the ternary conditional operator in the first place, there’s no need

  • 0

If you hate the ternary conditional operator in the first place, there’s no need to reply 😉

I usually see this used in tandem with an assignment expression like:

var foo = (some_condition) ? then_code : else_code;

However, I’d like to use it to replace simple code like:

if(some_condition) {
  do_something_simple;
} else {
  do_something_else;
}

and instead do:

(some_condition) ? do_something_simple : do_something_else;

I’m likely to be doing this in JavaScript. In the above it returns undefined so it doesn’t require the assignment. I like the space saved but wonder what folks think on this type of use as, again, I usually only see ternary used with an assignment.

EDIT: I’ve seen answers alluding to “hiding intent”. Although classically used in expressions, how is this hiding the intent any more then using in an expression? Especially in a dynamic language where one may see the use of ternary operators all over the place?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:30:27+00:00Added an answer on May 17, 2026 at 11:30 pm

    The conditional operator should normally be used in expressions – value producing expressions – and is best not used as a replacement for the ‘if/then/else’ statement. Used occasionally, there’d be no particular problem; used systematically, I think it would be hiding the intent of the code from the readers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hate to post this but I am on a time crunch and need
I hate to even ask this as there are plenty of examples with regard
I hate posting this since it's somewhat subjective, but it feels like there's a
I hate even bringing this up b/c there are so many hundreds of pages
I hate to be the third person to ask this, but the previous two
I hate that I'm doing this but I've just started working with Javascript classes
I hate that google can not search for symbols. I saw this in some
I hate starting a post with this but I'm new to Java... I've followed
I hate to ask another how do you do this with regex question on
I hate to do this, but I just can't identify what I am doing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.