JavaScript is partly an object-oriented language.

To learn JavaScript, we got to learn the object-oriented parts of JavaScript.

In this article, we’ll look at object properties.

Enumerating Properties

We can enumerate properties of an object with the for…in loop.

For example, if we have:

const obj = {
  a: 1,
  b: 2

We can write:

const obj = {
  a: 1,
  b: 2
for (const key in obj) {
  console.log(key, obj[key]);

Then we get:

a 1
b 2

The key has the key and obj[key] has the value.

Not all properties are enumerable, we can set the ebumerable property descriptor to make a property not enumerable.

We can check with the propertyIsEnumerable() method to check if a property is enumerable.

We can do the check with:


then we should get true since object properties are enumerable unless it’s specified otherwise.

#javascript #programming

Object-Oriented JavaScript — Prototype Catches
1.10 GEEK