Different Ways to Check if an Object is Empty in JavaScript

Learn different ways to check if an object is empty Photo by Felix Mooneeram on Unsplash 1. Using Object.keys Object.keys will return an Array, which contains the property names of the object. If the length of the array is 0, then we know that the object is empty. function isEmpty(obj) { return Object.keys(obj).length === 0;} We can …

CSS Animation Events in JavaScript

Learn how to detect animation events in JavaScript Photo by Pankaj Patel on Unsplash In JavaScript we can detect animation events . The list of available animation events are animationstart → Triggered when an animation is started animationiteration → Triggered on each iteration of animation animationend → Triggered at the end of animation animationcancel → Triggered when …

Terminal Commands to Save Time and Make You More Productive

Learn essential terminal commands for every developer Photo by Mika Baumeister on Unsplash If you’re a programmer, then most of the time you will be using the terminal. This article lists some of the most important Mac/Linux terminal commands. Basic Commands clear → Clears the screen. Alternatively, we can use Cmd + K . reset → Resets …

Learn BigInt in JavaScript

Learn how to use BigInt in JavaScript to store large numbers Photo by Mika Baumeister on Unsplash BigInt is a built-in object that provides a way to store numbers larger than Number.MAX_SAFE_INTEGER. The reason for the need of BigInt is var maxIntNum = 9007199254740991; var largeNumber = maxIntNum + 2; // 9007199254740992 The expected result for the …

Accessing an Object’s Keys, Values, and Entries in JavaScript

Let’s dive into objects Photo by Matt Artz on Unsplash Object.keys(obj) → returns an array of a given object’s property names. Object.values(obj) → returns an array of a given object’s own property values. Object.entries(obj) → returns an array of a given object’s own string-keyed property [key, value] pairs. var user = { name : “John”, profession : …

Redirect, Refresh, and Access the URL of the Current Page in JavaScript

JavaScript’s location object Photo by Javier Allegue Barros on Unsplash We can use the window.location property to access the URL of the current page and modify it. let location = window.location; For redirecting the page we can use: location.href = “new url”; // or we can use location.assign(“new url”); For redirecting without storing in history: location.replace(“new url”); …

Understand the Superpower of Optional Chaining in JavaScript

Learn how to use upcoming JavaScript feature Optional chaining ?. → Optional Chaining operator Image from twitter by Daniel Rosenwasser (@Daniel Rosenwasser). Optional Chaining Optional chaining will eliminate the need for manually checking if a property is available in an object . With optional chaining the checking will be done internally . Example without Optional chaining. function sayHi(user) …

Understanding the Sort Method of Arrays

How to use JavaScript’s sort Photo by Jozsef Hocza on Unsplash The JavaScript array sort() is used to sort array elements. By default, the array will sort in ascending order, but we can change it. This method will change the original array. We can also provide our comparing function to implement custom sorting. var array = …

Understand browser readyState and how to track the interactivity of the content on your web page

Learn how to handle the browser events and the state of the document for loading, interactive, and complete Different readyState of a document The current state of the document can be accessed using readyState property of the document object. document.readyState tells us the status of the page load. There are 3 different possible states: loading — The document is …

11 Extremely Useful JavaScript Tips

Level up your JavaScript game Image by David Monje from Unsplash 1. Converting to Boolean Using the !! Operator Sometimes, we need to check if a variable exists or if it has a valid value, to consider them as a true value. For this kind of validation, you can use the !! (double-negation operator). A simple !!variable, which will automatically …

Design a site like this with WordPress.com
Get started