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?
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. :)
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 verboseArray.isArray
. Wrapping a function that does exactly what you want with another function seems overkill to me. Don't you think?Otherwise, great job!
Just use typeof
nope:
An array is an
object
. Whether it's anArray
is a separate question. I suppose iftrueTypeOf
were documented, describing its semantics, it would be clearer. Remember, all, syntax doesn't convey everything. You also need semantics. :)Can you explain what this does and where you can put this in practice?
Check out this post for possible case use:
dev.to/cherif_b/using-javascript-t...
Yeah, sometimes it's handy to just call a function to check, rather than doing
Array.isArray(arr)
you know.