A guide to the different ways to create objects in JavaScript using a unique example.

In an attempt to fully absorb the various object creation patterns in JavaScript, in this article, we’re going to explore them through an example. Let’s define them, first, though:

  1. Object factories or factory functions pattern

Okay. So we’ll create some of the X-Men using all of the different patterns to see, in practice, how they work, as well as what their differences and similarities are.

  1. Object factories
    Object factories (aka factory functions) are perhaps, the simplest object creation pattern. We define a function that returns an…

This is a trap I’ve found myself falling into several times.

Photo by NeONBRAND on Unsplash

Although the Array.prototype.forEach() method seems like a good pick when you want to loop over an array of elements in JavaScript, there are several occasions when a simple for loop or another one of the built-in array methods is what you need.

Let’s create a simple example of a bad use case of the forEach method:

let array = [1, 2, 3];array.forEach(num => num += 1);

forEach accepts a callback function as an argument (num => num += 1), which in turn has one parameter, num. This parameter…

Four big fat complaints.

a laptop with code on the screen next to three plant pots in front of a window
a laptop with code on the screen next to three plant pots in front of a window
Photo by Safar Safarov on Unsplash

Last December, after having been searching for over a month what on 🌎 to do with my life (that is, after 4 years of going all the wrong ways), it seemed like I had finally found a direction to head toward when I stumbled on Web Development. Naturally, I was seeing all these terms like front-end developer, back-end, full-stack, computer science, software engineer, UI, UX and it was all Greek to me — except they weren’t cause I speak Greek.

And so I began looking for a course to follow along and after several days I found Udemy and I…

Antonina Kallinteri

Studying Software Engineering @Launch School

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store