7 useful JavaScript tips

Tram Ho

Just like any other programming language, JavaScript has many tricks to perform both tasks. Some of the tips are widely known:

Get the unique values ​​of an array

Getting an array of unique values ​​might be easier than you think:

Array and Boolean

Ever need to filter falsy values ​​(0, undefined, null, false, etc.) from an array? You may not know this trick:

Create blank Objects

Sure, you can create an empty Object with {}, but that Object still has the proto , hasOwnProperty, and other object methods. However, there is a way to create a pure “dictionary” object:

Merge objects

Require Function Parameters

It is possible to set default values ​​for function arguments, but see this tip to request the values ​​passed to a given argument:

Destructuring Aliases

Very useful to avoid naming conflicts with existing variables!

Get the query string parameter

We often use multiple expressions to retrieve query string values, but it’s now easier with the URLSearchParams API:

Refer here

Share the news now

Source : Viblo