Rules for comparing numbers in JavaScript

Nothing can be simpler than comparing two numbers. However, there are some details that you need to know about comparing numbers in JS. ...

February 4, 2022 路 1 min 路 Coderslang Master

Zero and Minus Zero in JavaScript

In JavaScript, there are 2 different zeros. A regular 0 is a bit different from -0 in JS. ...

February 3, 2022 路 1 min 路 Coderslang Master

Strict Equality in JavaScript

You can check strict equality in JavaScript using the operator ===. This operator does strict comparison and considers the operands equal if they鈥檙e of the same type, and their values are equal. ...

February 2, 2022 路 1 min 路 Coderslang Master

The difference between invisible and hidden HTML elements

In HTML there are 2 ways to hide an element. You can either make it invisible or make it hidden. The difference between a hidden HTML element and an invisible one is the amount of space occupied by the HTML element....

February 1, 2022 路 1 min 路 Coderslang Master

What is the difference between single and double quotes in JavaScript

There鈥檚 no functional difference between single and double quotes in JS. Both could be used to create JavaScript strings. Mostly it鈥檚 just about the code style that鈥檚 used in your project....

January 31, 2022 路 1 min 路 Coderslang Master

How to remove duplicates from a JavaScript array

There are multiple ways you can remove duplicates from a JS array. My favorite one is by using a Set and a spread operator. ...

January 30, 2022 路 1 min 路 Coderslang Master

Format a JavaScript Number to a Currency String

You can use the function toLocaleString or Intl.NumberFormat to get a formatted currency string from the JavaScript number. Here鈥檚 how it works. ...

January 29, 2022 路 1 min 路 Coderslang Master

How to empty an array in JavaScript

One of the easiest ways to empty a JS array is to set its length to zero. Alternatively you can use the functions pop or splice. Empty a JavaScript array by setting its length to 0 The length property holds the size of an array in JS....

January 28, 2022 路 1 min 路 Coderslang Master

How to check if a variable is a string in JavaScript

To check that a JS variable is of a type string, you can use 2 operators: instanceof and typeof. Here鈥檚 a quick solution. if (typeof text === 'string' || text instanceof String) { // it's a string!...

January 27, 2022 路 1 min 路 Coderslang Master

Get random number in a range using JavaScript

To get a random number is JS you almost always rely on the function Math.random. The only issue is that it returns a number between 0 and 1. You can generate a number in a specific range by writing a straightforward function....

January 26, 2022 路 1 min 路 Coderslang Master