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

  • Home
  • SEARCH
  • 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 7647187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:24:10+00:00 2026-05-31T10:24:10+00:00

I have 3 variables, that are not always set. o1 , o2 , o3

  • 0

I have 3 variables, that are not always set. o1, o2, o3.

I want to create a new variable as follows:

if none are set: o4 = null

if o1 is set, o4 = o1, regarded of what the other are.

when o1 is not set and o2 is set: o4 = o2

So o4 = o3 only gets set when 1 and 2 are not set.

==

I am now using a long switch, but I bet it can be done better.

JavaScript / jQuery

    var tmpl = '';

    if(data.o3 != null)
        tmpl = data.o3;

    if(data.o2 != null)
        tmpl = data.o2;

    if(data.o1 != null)
        tmpl = data.o1;
  • 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-31T10:24:11+00:00Added an answer on May 31, 2026 at 10:24 am

    Try var o4 = o1 || o2 || o3.

    Edit: As per comments, this only works when values that might be set are not falsy. May be best to avoid this method, unless you’re sure.

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

Sidebar

Related Questions

Basically I have some variables that I don't want to preinitialize: originalTime = None
I have certain PHP class methods that access external variables. These variables are not
I have a variable in my xsl that may or may not be declared.
I have some user-submitted variables that I want to display in a different part
Does Java have a default System Environment Variable that will always be read/appended when
I have double (or float) variables that might be empty, as in holding no
I have objects with many variables that I declare and explain in the comments.
I have a template I made that sets variables that rarely change, call my
I have a big list of global variables that each have their own setup
I was wondering if this was possible... I have a sequence of variables that

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.