DEV Community

Discussion on: 20 JavaScript One-Liners That Will Help You Code Like a Pro

Collapse
 
aminnairi profile image
Amin

Hi there, really cool one-liners! My favorite is the true type one. I actually use it in almost all of my projects.

I'm not sure about the isArray though. This is indeed a one-liner, but in my opinion, it does not add much, besides being a shorter named version of the verbose Array.isArray. Wrapping a function that does exactly what you want with another function seems overkill to me. Don't you think?

Otherwise, great job!

Collapse
 
matthewadams profile image
Matthew Adams

Just use typeof

Collapse
 
andreykalechev profile image
Leechy

nope:

typeof []
// "object"
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
matthewadams profile image
Matthew Adams

An array is an object. Whether it's an Array is a separate question. I suppose if trueTypeOf were documented, describing its semantics, it would be clearer. Remember, all, syntax doesn't convey everything. You also need semantics. :)

Collapse
 
galoelmer profile image
galoelmer

Symbol.toStringTag

Collapse
 
robinbastiaan profile image
Robin Bastiaan

Can you explain what this does and where you can put this in practice?

Thread Thread
 
galoelmer profile image
galoelmer

Check out this post for possible case use:
dev.to/cherif_b/using-javascript-t...

Collapse
 
ovi profile image
Muhammad Ovi

Yeah, sometimes it's handy to just call a function to check, rather than doing Array.isArray(arr) you know.