I've been a little busy building cenario over the past few months and shining my coding skills again.
During this period I remembered/learnt a lot of simple tricks that might be useful for beginners or people looking to quickly upgrade their syntax knowledge
So here we go 🚀:
I used to use _.get from lodash, but since a little while I'm using a babel preset to use this pattern
PS this is available in Node 14, but if you want to use it in your current project you can use the optional chaining babel plugin
It gets a little clunky to reference the same nested variable within the function, that could have been done on the argument level.
Naming variables is tougher than people think. Combine that with my low with destructuring, I found it painful that variables would conflict whenever I would destructure. This has been in my pocket for a few years now
I've stayed away from splice actively, just from seeing its internal working and knowing how slowly it operates. Yes you can also use splice for this
Super simple shortcut
Okay I'm kidding, this is not typescript, but hey you can set arguments to be required values, vs doing null checks within the function
This is a doozy and has been for so long, lodash has a uniq method too, I used to use that a lot until I remembered good mate JS allows for Sets and Maps (a topic for another day)
So you can create an array with unique values, in a very performant way, and in a clean way using Sets
Sometimes you want to ensure there's at least some default value set to the arguments of your function
There you go, all simple things and most importantly they don't ruin readability (like many hacks)
Hope you enjoyed this! Looking forward to getting more active again!