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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:41:50+00:00 2026-06-04T11:41:50+00:00

After testing out instasnceof I found that it will return true if the argument

  • 0

After testing out instasnceof I found that it will return true if the argument is an array or an object literal.

function test(options){
  if(options instanceof Object){alert('yes')}//this will alert for both arrays and object literals
}
test({x:11})// alerts
test([11])// alerts as well but I do not want it to

Is there a way to test if the argument “options” is an object literal?

P.S. I am creating a module that will allow the user to access its configuration options, and I want to test if the argument is only an object literal or not?

  • 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-06-04T11:41:52+00:00Added an answer on June 4, 2026 at 11:41 am

    is there a way to test if the argument “options” is an object literal?

    No, because it makes no sense. You can test whether it’s an object, but how it was created (via a literal in the call to your function, via a literal elsewhere, through new Object, by deserializing a JSON string, …) is not information that’s maintained.

    after testing out instasnceof i found that it will return true if the argument is an array or an object literal

    Correct. Arrays in JavaScript are objects (and not really arrays).

    If you want to test that an object is a plain old object, you can do this:

    if (Object.prototype.toString.call(options) === "[object Object]") {
        // It's a plain object
    }
    

    But there’s really no reason to do that. It’s not your problem. As long as what they pass you has the properties you expect, don’t try to limit the object further.

    p.s. i’m making a module that will allow the user to pass it configuration options and i want to test to make sure that the argument is only an object literal.

    Why? If the user wants to use an object that hasn’t been declared as a literal right there and then, why would you care? If they want to use an object that they’ve created via a different constructor function (e.g., rather than just a plain object), again, why would you care?

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

Sidebar

Related Questions

I found out after testing that linux allows any character in a file name
After switching from firefox testing to internet explorer testing, some elements couldn't be found
I'm testing out http://code.google.com/p/jquery-loadmask/ where it unmasks after an ajax call: $(#content-container).mask(Waiting...); $.ajax({ url:
After testing a small site that I built for my school in Firefox, SeaMonkey,
I've uploaded a simple Azure website (am testing out authentication) and have found this:
I have a script that I wrote in python for testing out the sorting
[Edited: After cross-testing on a fresh machine and some additional research, this appears to
After much googling and console testing I need some help with arrays in rails.
I'm a newbie to Unit Testing and I'm after some best practice advice. I'm
After loosing much sleep I still cannot figure this out: The code below (its

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.