The Object keys() method

Learn everything you need to know about the JavaScript keys() method of the Object object. The Object.keys() method takes an object as an argument and returns an array of all its (own) enumerable properties. const car = { color: 'Blue', brand: 'Ford', model: 'Fiesta' } Object.keys(car) //[ 'color', 'brand', 'model' ] Here, “enumerable properties” refers to properties whose internal enumerable flag is set to true, which is the default behavior. To dive deeper into this concept, you can refer to the documentation on enumerability and ownership of properties on MDN....

The Object.freeze() Method: A Deep Dive

In JavaScript, the freeze() method of the Object object plays a vital role. This method takes an object as an argument and returns the same object with a significant change. The object passed as an argument becomes immutable - meaning that no properties can be added, removed, or modified. Let’s take a look at an example: const dog = {} dog.breed = 'Siberian Husky' const myDog = Object.freeze(dog) Object.isFrozen(dog) // true Object....

The Optimal Path to Mastering React

Learning React may seem like a daunting task, but with the right resources and a consistent approach, you can become a React master. In this blog post, we will guide you through the optimal path to go from zero to proficient in React. Before diving into React, it’s essential to have a solid understanding of JavaScript. If you are just starting out, take the time to explore the fundamentals of JavaScript....

The parseFloat() Method in JavaScript

Introduction In JavaScript, the parseFloat() method is part of the Number object. It is used to parse a string argument as a floating-point number and return the parsed value. This method is particularly useful when you need to convert a string representation of a number into an actual number. Syntax The syntax for using the parseFloat() method is as follows: Number.parseFloat(string) Examples Here are some examples demonstrating the usage of the parseFloat() method:...

The parseInt() Method in JavaScript

In this blog post, we will explore the parseInt() method of the Number object in JavaScript. The parseInt() method is used to parse a string argument and convert it into an integer number. Let’s take a closer look at how it works and its various use cases. Basic Usage The parseInt() method can be used with a string argument, and it will return the parsed integer value. Here are some examples:...

The preventExtensions() Method in JavaScript

In JavaScript, the preventExtensions() method is used with the Object object. This method takes an object as an argument and returns the same object. The preventExtensions() method modifies the object, making it unable to accept new properties. However, it still allows for the removal and modification of existing properties. Here is an example: const dog = {} dog.breed = 'Siberian Husky' Object.preventExtensions(dog) dog.name = 'Roger' // TypeError: Cannot add property name, object is not extensible In this example, we create a new object called dog and assign the property breed with the value 'Siberian Husky'....

The repeat() Method in JavaScript

The repeat() method in JavaScript, introduced in ES2015, allows you to repeat a specified string a certain number of times. It can be useful in situations where you need to generate repetitive patterns or output repeated text. Here’s an example of how to use the repeat() method: 'Ho'.repeat(3); // 'HoHoHo' In this example, the string “Ho” is repeated three times, resulting in the output “HoHoHo”. If you call the repeat() method without any parameters or with a parameter of 0, it will return an empty string:...

The Set JavaScript Data Structure

The Set data structure in JavaScript allows you to store and manage a collection of objects or primitive types. It is similar to a Map, where the values are used as keys and the map value is always a boolean true. Table of Contents What is a Set? Initialize a Set Add items to a Set Check if an item is in the set Delete an item from a Set by key Determine the number of items in a Set Delete all items from a Set Iterate the items in a Set Initialize a Set with values Convert to array Convert the Set keys into an array A WeakSet What is a Set?...

The setPrototypeOf() Method in JavaScript

Learn all about the setPrototypeOf() method in the JavaScript Object object. Setting the prototype of an object is made possible with the setPrototypeOf() method. To dive deeper into JavaScript Prototypal Inheritance, check out my comprehensive guide here. Syntax: Object.setPrototypeOf(object, prototype) Example: const Animal = {} Animal.isAnimal = true const Mammal = Object.create(Animal) Mammal.isMammal = true console.log('-------') Mammal.isAnimal // true const dog = Object.create(Animal) dog.isAnimal // true console.log(dog.isMammal) // undefined Object.setPrototypeOf(dog, Mammal) console....

The Stack Data Structure in JavaScript: Explained and Implemented

A stack is a data structure that comes with certain limitations, contrasting it with arrays. In a stack, we can only add items on top and remove the top item. Think of it like a pile of books, where you can only add books to the top and remove the one on top. This behavior is known as First In, Last Out (FILO). While arrays in JavaScript are already built-in and readily available, we still need to implement stacks ourselves....