What are getters and setters in JavaScript

In JavaScript, you may have heard of getters and setters. Let’s take a look at what these things are.First, a setter is used to set the value of a property. A setter gets called each time the value of the property is changed. In other words, it executes a function for each time a property … Continue reading What are getters and setters in JavaScript

Advertisements

JavaScript Object Property Descriptors

In JavaScript, you can create an object literal as shown in the listing below:At first sight, it looks like the object cat has two properties with a string and number value. However, it’s much more than that to a JavaScript interpreter. In ES5, the concept of a Property Descriptor was introduced. Before we go ahead … Continue reading JavaScript Object Property Descriptors

Simplifying function hoisting in JavaScript

To understand function hoisting, let us start by considering the code listed below:In any other programming language, the output here would be a reference error. However, in JavaScript you will get undefined as the output. Why? Because JavaScript hoists variables at the top of the execution context. An execution context could be the function in … Continue reading Simplifying function hoisting in JavaScript