Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
May 7, 2020 06:54 am GMT

8 Ridiculously Simple Javascript Tricks Not Taught on Tutorials

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 :

Null checker

I used to use _.get from lodash, but since a little while I'm using a babel preset to use this patter

Alt Text

Destructuring Arguments in a function

It gets a little clunky to reference the same nested variable within the function, that could have been done on the argument level.

Alt Text

Reallocating variables

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

Alt Text

Staying away from splice

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

Alt Text

Maintaining the context of this easily in objects

Super simple shortcut

Alt Text

Typescript without Typescript

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

Alt Text

Unique array

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

Alt Text

Default away

Sometimes you want to ensure there's at least some default value set to the arguments of your function

Alt Text

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!

twitter: twitter.com/@veebuv
linkedin: linkedin.com/in/vaibhavnamburi
instagram: _veebuv


Original Link: https://dev.to/veebuv/8-ridiculously-simple-javascript-tricks-not-taught-on-tutorials-2f7o

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To