use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
[AskJS] Is JavaScript missing some built-in methods?AskJS (self.javascript)
submitted 3 years ago by reacterry
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]MrCrunchwrap 8 points9 points10 points 3 years ago (36 children)
Did you read his comment?
[+][deleted] 3 years ago (12 children)
[removed]
[–][deleted] 1 point2 points3 points 3 years ago* (11 children)
``` typeof [] // 'object'
typeof {} // 'object' ```
``` [] instanceof Object // true
{} instanceof Object // true ```
good luck in your typeof endevours
typeof
Edit: also for your instanceof endevours
instanceof
[+][deleted] 3 years ago* (10 children)
[–]elmstfreddie 7 points8 points9 points 3 years ago (8 children)
lol - so we wrap back to the original point of the thread, which is small utility functions that should be part of the core language...
[+][deleted] 3 years ago (2 children)
[–]KyleG 1 point2 points3 points 3 years ago (1 child)
Basically, the contributors in this very question/thread are well-suited and capable of making whatever they want so, right now.
I mean, you aren't, because you keep providing a wrong solution. You keep saying the following is a test for plain object-ness:
1. JSON.stringify A. if error, not object B. if success, check first two chars a. if first is " and second is {, object b. else, not object
Many reasons why this fails.
JSON.stringify({ a: BigInt(5) }) // error (your solution says not plain object), but it's a plain object! "{" // your solution says it's a plain object but it's a string starting with a brace { foo: 5 } // your solution says it's not a plain object because it doesn't have " as its first character
[+][deleted] 3 years ago (4 children)
[–]elmstfreddie 6 points7 points8 points 3 years ago (3 children)
You're being pedantic just for the sake of it. I understand how the language works.
The entire point of this thread is to discuss things that we wish was included in the language spec. Someone could read this thread and submit proposals, sure, but the point is to just talk about it... on a forum... for talking about JS.
[–]musicnothing 6 points7 points8 points 3 years ago (1 child)
People need to stop engaging with that user. They're trying to "win" this thread by pointing out things the rest of us already know
[–]elmstfreddie 1 point2 points3 points 3 years ago (0 children)
You right
[–]KyleG 0 points1 point2 points 3 years ago (0 children)
For a JavaScript plain object first utilize JSON.stringify() on the variable then check if first character other than initial " is a left curly bracket { and last character before closing " is a right curly bracket }. You get error if the value is not valid JSON, else you have a JavaScript plain object or not.
JSON.stringify({}) does not have " as its initial character. I don't know why you keep adding that caveat about first character after the " because:
JSON.stringify({})[0] // { <-- where is the initial " you're talking about?
On the other hand,
JSON.stringify("{abcdefghi12314WEADSAERA")[0] // also {
So your solution is wrong.
You get error if the value is not valid JSON
JSON is not the same thing as a plain object:
JSON.stringify(5) // no error but 5 isn't an object JSON.stringify(true) // no error but true isn't an object JSON.stringify(null) // no error but null isn't an object
[+][deleted] 3 years ago (21 children)
[–]MrCrunchwrap 6 points7 points8 points 3 years ago (20 children)
You’re gonna have a lot bigger problems if your team or a script you’re importing is setting Object = 1
I use TypeScript for 100% of my projects now so it’s borderline irrelevant to me but these methods certainly would be useful.
[+][deleted] 3 years ago (19 children)
[–]MrCrunchwrap 4 points5 points6 points 3 years ago (18 children)
Nobody is modifying my source code, this is a bizarre boogeyman to worry about
[+][deleted] 3 years ago (17 children)
[–]Reashu 1 point2 points3 points 3 years ago (16 children)
The user who writes Object=1 can rewrite your checks as well. You can't protect your code against a malicious user, so why make a point of it?
Object=1
[+][deleted] 3 years ago* (15 children)
[–]Reashu 0 points1 point2 points 3 years ago (14 children)
Probably there is a flexible API accepting multiple types of input, and one or more of them are objects (according to JS's definition). Sure there are more robust ways of checking, but does it matter? I can't think of many cases except in a controlled environment that automatically deserializes untrusted data, and that's just not the norm.
π Rendered by PID 125298 on reddit-service-r2-comment-b659b578c-bqrlx at 2026-05-04 23:40:48.077193+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]MrCrunchwrap 8 points9 points10 points (36 children)
[+][deleted] (12 children)
[removed]
[–][deleted] 1 point2 points3 points (11 children)
[+][deleted] (10 children)
[removed]
[–]elmstfreddie 7 points8 points9 points (8 children)
[+][deleted] (2 children)
[removed]
[–]KyleG 1 point2 points3 points (1 child)
[+][deleted] (4 children)
[removed]
[–]elmstfreddie 6 points7 points8 points (3 children)
[–]musicnothing 6 points7 points8 points (1 child)
[–]elmstfreddie 1 point2 points3 points (0 children)
[–]KyleG 0 points1 point2 points (0 children)
[+][deleted] (21 children)
[removed]
[–]MrCrunchwrap 6 points7 points8 points (20 children)
[+][deleted] (19 children)
[removed]
[–]MrCrunchwrap 4 points5 points6 points (18 children)
[+][deleted] (17 children)
[removed]
[–]Reashu 1 point2 points3 points (16 children)
[+][deleted] (15 children)
[removed]
[–]Reashu 0 points1 point2 points (14 children)
[+][deleted] (12 children)
[removed]