How to Format a JavaScript Date

You can format the date in JS by using the toLocaleDateString function. It accepts a locale and returns a string with formatted date. Let鈥檚 try to use the locale en-US....

January 17, 2022 路 1 min 路 Coderslang Master

How to implement sleep function in JavaScript

JavaScript is asynchronous by design, so implementing a sleep function can be tricky. The closest you can get to pausing execution for some time is by using Promise and await....

January 17, 2022 路 1 min 路 Coderslang Master

How to create a multiline string in JavaScript

The easiest way to create a multiline string in JavaScript are backticks. const s = `I'm a multiline string`; console.log(s); The console output shows every word in the string s on a new line....

January 16, 2022 路 1 min 路 Coderslang Master

Convert a string to boolean in JavaScript

As obvious and easy as it may sound, converting string values of "true" and "false" to booleans can be tricky. There are many ways to shoot our own foot, if you don鈥檛 know how JavaScript works under the hood....

January 15, 2022 路 1 min 路 Coderslang Master

Detect an undefined object property in JavaScript

In JavaScript there are 2 distinct scenarios when the object property can be undefined. Let鈥檚 look into them and find out how to check for undefined fields in JS objects. ...

January 14, 2022 路 2 min 路 Coderslang Master

How to check if a variable is an array in JavaScript

If you try to apply the typeof operator to a JavaScript array, you won鈥檛 be able to tell if it鈥檚 an array. To check if a variable is an array in JS, you need to take a different approach. ...

January 13, 2022 路 1 min 路 Coderslang Master

How to get current URL in JavaScript

There are 2 ways to get the current URL from a browser using JavaScript. The main one is window.location.href and document.URL is an alternative option. ...

January 12, 2022 路 1 min 路 Coderslang Master

What is a double negation !! in JavaScript and how it works

Double negation is a common JavaScript trick that allow you to convert different types to boolean. Here鈥檚 how double negation works in JS. ...

January 11, 2022 路 1 min 路 Coderslang Master

How to copy to clipboard in JavaScript

There are 3 main ways you can copy something to clipboard with JavaScript. The main one is the Async Clipboard API. It reads the text from DOM and places it on the clipboard. ...

January 10, 2022 路 1 min 路 Coderslang Master

How to get a timestamp in JavaScript

Every date in JS can be represented as a number of milliseconds since Jan 1, 1970. Here鈥檚 how you can get the timestamp value from any JavaScript date. ...

January 9, 2022 路 1 min 路 Coderslang Master