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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:54:03+00:00 2026-05-30T15:54:03+00:00

x = ( typeof x != ‘undefined’ && x instanceof Array ) ? x

  • 0
x = ( typeof x != 'undefined' && x instanceof Array ) ? x : [];

I understand that if x is defined and it is an array it will do everything between ? and : then if undefined or it is not an array it will do []. what is []?

Does anyone know where i can get examples of how this works and other shorthand techniques or can you explain what is happening here?

I just really dont understand how it is creating an array

  • 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-30T15:54:05+00:00Added an answer on May 30, 2026 at 3:54 pm

    [] is an empty array.

    So if x is undefined or not an array, then it is set to an empty array.

    This is the same as:

    if (!( typeof x != 'undefined' && x instanceof Array )) {
        x = [];
    }
    

    There is more information on the Conditional (Ternary) Operator here:

    http://msdn.microsoft.com/en-us/library/windows/apps/be21c7hw%28v=vs.94%29.aspx

    Another useful shorthand for default arguments is:

    function (x) {
        x = x || 7;
    }
    

    This is set x to 7 as long as x == false (i.e. x is not null, undefined, false, '' (empty string), or 0)

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

Sidebar

Related Questions

Can this code if (typeof foo != undefined && foo !== null) { }
Is there a difference between typeof value === undefined and value === undefined ?
function isVowel(char){ if(typeof char == 'string' && char.length > 1){ console.log('not a char'); return
typeof(int).Name Will return System.Int32 does anyone know of a way to return int
Founded that: typeof(System.Enum).IsClass == false It's become strange that System.Enum has also .IsValueType ==
When using ECMAScripts typeof on plugin elements (i.e. embed or object ), Safari &
Apparently neither instanceof nor typeof deliver in terms of correctly identifying the type of
It is commonly known that typeof null returns object. However, I have a piece
Tried: var xxx = (typeof my_var.property !== 'undefined') ? my_var.property : 'fu'; I get:
If I write: var type = typeof(List<string>); Console.WriteLine(type.Name); It will write: List`1 I want

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.