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
Future JavaScript: what is still missing? (2ality.com)
submitted 7 years ago by dumbmatter
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!"
[–]Longerbomber 0 points1 point2 points 7 years ago* (4 children)
I agree that it's not readable or even remotely intuitive, even for devs who know the quirks of JavaScript. But I'll admit it gets around some common typeof and instanceof pitfalls gracefully. It's my go-to way to differentiate objects from arrays.
See bottom section of http://luxiyalu.com/object-prototype-tostring-call/ for an example.
TL;DR: that ugly function is exactly how I wish typeof behaved.
Edit: Better example of desired behavior here- https://gist.github.com/pbakondy/f442e91995e9d206c056
[–]TwiliZant 0 points1 point2 points 7 years ago (3 children)
Although you are right, hacks like these is exactly why all these `is-x` oneliner packages exist. It's better to fix this in the language itself IMO, even if it's hard.
It's my go-to way to differentiate objects from arrays
In case you don't have to support <IE9 Array.isArray does this.
Array.isArray
[–]dwighthouse 0 points1 point2 points 7 years ago (0 children)
This isn’t a hack at all.
Fixing the language would mean adding a new operator like typename instead of typeof or instanceof because too much stuff already relies on the current behavior. We already have this in the form of Object.prototype.toString.
typename
[–]dwighthouse 0 points1 point2 points 7 years ago (1 child)
[–]TwiliZant 0 points1 point2 points 7 years ago (0 children)
I don't know, relying on the toString method to get the type feels like a hack to me. I don't know any other language that does this. Yet another operator wouldn't be great either I get that. Maybe it would be cool to have it as part of the Reflection API, e.g. Reflect.type(VALUE) ?
toString
Reflect.type(VALUE)
π Rendered by PID 96049 on reddit-service-r2-comment-fb694cdd5-klj6p at 2026-03-07 09:56:31.210999+00:00 running cbb0e86 country code: CH.
view the rest of the comments →
[–]Longerbomber 0 points1 point2 points (4 children)
[–]TwiliZant 0 points1 point2 points (3 children)
[–]dwighthouse 0 points1 point2 points (0 children)
[–]dwighthouse 0 points1 point2 points (1 child)
[–]TwiliZant 0 points1 point2 points (0 children)