Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

20
  • 4
    @zupa: what !!a does? Commented Apr 23, 2015 at 10:59
  • 10
    @3000 well, if we leave out the (!!a) part it crashes, because null and undefined have no constructors. (!!a) filters them out. Does that answer your question? Commented Apr 27, 2015 at 15:26
  • 3
    @zupa @3000 Boolean(a) is longer, but far more intuitive. Just don't use new Boolean(a): (here's why)! Commented Aug 20, 2015 at 13:32
  • 30
    Surprised the best answer is so far down the page. This basically answers the question- would this be represented in JSON as something starting with a { character. For the array case, as long as you don't need to support IE < 9, you can use Array.isArray() to determine if something is an array. It passes all the test cases you provided. Commented Mar 10, 2016 at 14:56
  • 4
    @BradKent Without the double negative !!a isObject(null) would return null instead of false Commented Aug 13, 2019 at 22:43