
In this post I will share useful hacks for JavaScript. These hacks reduce the code and will help you to run optimized code. So let’s start hacking!...
For further actions, you may consider blocking this person and/or reporting abuse
A few things:
typeof
example is missingtypeof
- oops! 😝Symbols
, string keys that are non-enumerable, and values coming from lower down in the prototype chain. For more information on this, you can look herejs
after the opening three backticks of the code blockThank you Jon Randy for highlighting some crucial points. I have updated the typeof function. There is more to learn. Thanks again for the useful links.
Might want to update it again, since
typeof
is an operator, not a function (as you initially correctly state) - and the data you are checking is the operand, not an argument to a function. For this reason, the parentheses in your example are unnecessary.Came here to say the same thing. "Hacks" are more of a thing for working around libraries/frameworks. Like using reflection to access a private property or something. Better title would have been something like "My favorite pieces of code"
Please don't use
&&
as a shortcut for conditional statements. It is harder to read and understand. You may want to use??
instead of||
if you just want to check if the value isundefined
ornull
.Readability and understand-ability are purely subjective.
Сongratulations 🥳! Your article hit the top posts for the week - dev.to/fruntend/top-10-posts-for-f...
Keep it up 👍
Good post, learn this things. Please share more!
Thank you.
Why did you only mention
console.table
when there are many other methods for the console likeconsole.group
,console.error
, console.warn` and many other super useful methods on the console object?Noteing something for readers, as article said typeof is an operator not a function
so it can also be used like an operator without prantesis.
value wrapped with prantesis is going to be evaluated to variable iteself.
Thanks, updated.
Thanks!
We could break this down into bite sized bits for other sharing formats
Wow!, Good to know