JavaScript: How to Disable a Button on Click
Updated: Mar 16, 2023
When building interactive websites (or web apps) with JavaScript, there might be cases where you want to disable a button after it gets clicked one time, for example, to prevent a user from submitting a form multiple times and causing......
JavaScript: 4 Ways to Get the Width & Height of an Element
Updated: Mar 16, 2023
This succinct, practical article will walk you through a couple of different ways to get the width and height of an element using JavaScript. Inspecting the Width & Height of an Element Let’s say we have an element with......
Using getters and setters in JavaScript classes
Updated: Mar 16, 2023
Introduction In JavaScript, getters and setters are special methods that allow a class to define how to access and modify its properties. They have many use cases, such as: Creating a read-only property that cannot be changed by......
Private, Protected, and Public Class Members in JavaScript
Updated: Mar 14, 2023
JavaScript classes, which were added in ECMAScript 2015 (ES6), are a way of creating objects with a common structure and behavior. They can have different kinds of members, such as properties (fields) and methods (functions). By......
JavaScript: Get the Width & Height of the Window
Updated: Mar 14, 2023
When developing modern websites and applications with JavaScript, there may be cases where we need to get the width and height of the window, such as to make responsive designs, to determine the available space for displaying content......
JavaScript: Renaming the Key of an Object’s Property
Updated: Mar 14, 2023
When writing code in JavaScript, there might be cases where you need to rename the key of an object’s property, such as to make the object keys more readable or consistent with a naming convention or to replace the keys based on......
JavaScript: 3 Ways to Check if an Object is Empty
Updated: Mar 14, 2023
This concise, straight-to-the-point article shows you a couple of different ways to check whether a given object is empty or not in JavaScript. Using the Object.keys(), Object.values(), or Object.entries() method One common approach......
JavaScript: Create an Object from Arrays of Keys and Values
Updated: Mar 14, 2023
This succinct, straightforward article walks you through 5 different approaches to creating an object from 2 arrays of keys and values in JavaScript. The main point here is to make sure the keys and values in the 2 arrays are aligned in......
JavaScript: 5 ways to add new properties to an existing object
Updated: Mar 14, 2023
This succinct, straightforward article will walk you through 5 different ways to add new properties to an existing object in JavaScript. We’ll write code with the modern feature of the language, such as arrow functions, spread......
JavaScript: Get the Key of an Object Property by Its Value
Updated: Mar 14, 2023
When developing websites and applications with JavaScript, there might be times when you need to retrieve the key of an object property by its value. This task can be done in several different ways. Let’s explore them, one by one,......
JavaScript: Convert a byte array to a hex string and vice versa
Updated: Mar 13, 2023
This concise and straightforward article shows you how to convert a byte array into a hex string (hexadecimal string) and vice versa in modern JavaScript (ES6 and above). Overview What are hex strings and byte arrays? A hex......
JavaScript: Finding the Mean (Average) of an Array
Updated: Mar 13, 2023
This succinct, practical article shows you some different ways to find the mean (the average value) of a given array in JavaScript (assuming that the array contains only numeric elements). Introduction Calculating the mean of an......