8 Ridiculously Simple Javascript Tricks Not Taught on Tutorials
Tags: beginners, javascript, es6, showcode
Published: 2020-05-07 06:54:19

---
title: 8 Ridiculously Simple Javascript Tricks Not Taught on Tutorials
published: true
description: Simple snippets explaining easy updated JS syntax to make your overall JS experience easier without compromising readability
tags: #beginner #javascript #es6 #showcode
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/kkjifjnex3r4vqjkt2f4.png
---

I've been a little busy building [cenario](https://cenario.co) 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 (optional chaining)

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

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/we77vijkqgvfwgfg7oe3.jpeg)

## 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](https://dev-to-uploads.s3.amazonaws.com/i/uddujtk7jpsca450bqpl.png)

## 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](https://dev-to-uploads.s3.amazonaws.com/i/hrve4ze725j3m4f1ms9r.png)

## 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](https://dev-to-uploads.s3.amazonaws.com/i/2g57p2sl2mm6wymdk3ff.png)

## Maintaining the context of this easily in objects

Super simple shortcut

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/qwvdpobbuinmsmh9t52q.png)

## 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](https://dev-to-uploads.s3.amazonaws.com/i/up63bcn2l33bjvzxmzxe.png)

## 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](https://dev-to-uploads.s3.amazonaws.com/i/o2axy1ygg1tpwki1nron.png)

## Default away

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

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/1x2x43jrmairpa38hyc8.png)

--------
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](twitter.com/@veebuv)
linkedin: [linkedin.com/in/vaibhavnamburi](linkedin.com/in/vaibhavnamburi)
instagram: [_veebuv](https://instagram.com/_veebuv)