Learn these Javascript Tips and Tricks!

Jacky Lin
2 min readNov 24, 2020
Photo by Christopher Robin Ebbinghaus on Unsplash

I want to share a couple of tips and tricks I learned from JS Knowledge

1. new Set

Picture an array with duplicate items and wanting to filter out all the duplicates. Of course you can try using map or filter but using Set can solve the problem in one line of code.

I have provided an integer example below:

2. “IF” statements can be shorten

This is a risky tip/trick because it can be messy. It is one way to shorten your if statements however if you write more complicated statements, its best to stick to the original.

3. Limit your array using the length property

This is given but thought it would be very useful for beginners. It is a great way to shorten the length to your desire by redefining its length property.

4. Spread Operator to combine objects

Lets pretend you need to combine multiple objects together, the best way to do that is using the spread operator[…].

Thanks for reading!

Thank you for reading, I enjoy writing these to help myself as well!

--

--