None of these are 'hacks' - they're just features of the language
Your typeof example is missing typeof - oops! 😝
Your shuffling example will give biased results (some shuffle permutations will turn up way more often than others - explanation here)
Your method for testing if an object has values is overly simplistic, and may result in you deleting objects that are, in fact, not empty. It will not include keys that are 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 here
You can add syntax highlighting to your examples by adding js after the opening three backticks of the code block
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"
Thank 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.
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 is undefined or null.
Why did you only mention console.table when there are many other methods for the console like console.group, console.error, console.warn` and many other super useful methods on the console object?
A few things:
typeofexample 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 herejsafter the opening three backticks of the code blockCame 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"
Thank 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
typeofis 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.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 isundefinedornull.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.
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.
Why did you only mention
console.tablewhen there are many other methods for the console likeconsole.group,console.error, console.warn` and many other super useful methods on the console object?Thanks!
Wow!, Good to know
We could break this down into bite sized bits for other sharing formats