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 7672447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:17:15+00:00 2026-05-31T16:17:15+00:00

In javascript I have an if statement and I want to log the first

  • 0

In javascript I have an if statement and I want to log the first condition that defaulted to true. For instance if a === true then I want to console.log a (update: e.g., “a” or “b” or “c”, the actual character).

Any ideas?

if(a || b || c){ console.log(this) }

Thanks guys!

  • 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-31T16:17:16+00:00Added an answer on May 31, 2026 at 4:17 pm

    The best thing to do is, of course, use a debugger and inspect a, b, and/or c when you branch into the if statement’s body. 🙂

    Doing it in code, there’s no shortcut if you’re really trying to see “a”, “b”, or “c” update what was I thinking? Of course there’s a shortcut:

    if(a || b || c){
        console.log(a ? "a" : b ? "b" : "c");
    }
    

    Or if you want to see the value as well:

    if(a || b || c){
        console.log(a ? "a: " + a : b ? "b: " + b : "c: " + c);
    }
    

    Live example | Live source


    Original longer version:

    if(a || b || c){
        if (a) {
            console.log("a: " + a);
        }
        else if (b) {
            console.log("b: " + b);
        }
        else {
            console.log("c: " + c);
        }
    }
    

    Or (and this is quite tricky and much longer, so not recommended):

    if(a || b || c){
        switch (false) {
            case !a:
                console.log("a: " + a);
                break;
            case !b:
                console.log("b: " + b);
                break;
            default:
                console.log("c: " + c);
        }
    }
    

    …which works because switch statement cases are evaluated at runtime, and in order.

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

Sidebar

Related Questions

I have problem in some JavaScript that I am writing where the Switch statement
I have a function that I want to return true or false. Inside the
I want to ask about optimisation in JavaScript if else statement.I have the code
Does Javascript or jQuery have sometime like the in statement in Python? a in
I have the following Javascript. The document.location statement produces an error as the URL
I have some third-party Javascript that has statements like this: FOO = function() {
Does jquery/javascript have any event model that you can attach to your objects? Basically
Javascript I have code that will hide various sections in a MS CRM form
I have Javascript that opens another window and registers a click handler for all
I have JavaScript that is doing activity periodically. When the user is not looking

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.