Member-only story

7 More Killer One-Liners in JavaScript

Tapajyoti Bose
3 min readApr 24, 2022

This is a continuation of the previous list of JavaScript one-liners. If you haven’t checked out the article, you are highly encouraged to accomplish so.

Let’s crack on with the new list!

1. Sleep Function

JavaScript has NO built-in sleep function to wait for a given duration before continuing the execution flow of the code.

Luckily, generating a function for this purpose is straightforward

const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

2. Go Back to the Previous Page

Need to send the user back to the page they came from? history object to the rescue!

const navigateBack = () => history.back();
// Or
const navigateBack = () => history.go(-1);

3. Compare Objects

Javascript behaves in mysterious ways when comparing objects. Comparing objects with the === operator checks only the reference of the objects, so the following code always returns false:

const obj1 = { a: 1, b: 2 };
const obj2 = { a

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Tapajyoti Bose
Tapajyoti Bose

Written by Tapajyoti Bose

Top Rated Freelancer || Blogger || Cross-Platform App Developer || Web Developer || Open Source Contributor || FIRE Enthusiast

Responses (14)

Write a response

I was gonna say that I think "steroids" are a bad analogy. But after I actually bothered to read up on them, I think the analogy is perfect.
Steroids just make you look tougher without making you tough. From my experience using TS for a couple of…

A steroid is a biologically active organic compound with four rings arranged in a specific molecular configuration. Steroids have two principal biological functions: as important components of cell membranes which alter membrane fluidity; and as signaling molecules.