Tag: Objects
-
Working with objects in a JavaScript Arrow Function
The JavaScript Arrow function is a shorter way of writing a function expression. Let us say you have a function expression as below, var add = function (num1, num2) { return num1 + num2; } The above function can refactor for a shorter syntax using the arrow function as below, var add = (num1, num2) => num1 + num2; So, as you see, the arrow function provides a convenient and short syntax…
-
How to use for…of loop with an Object in JavaScript
In my last post, I discussed Always Use the for…of loop to iterate in JavaScript. After this post, I got a question that, is it possible to use for…of loop with an object? Means, can you use the for…of loop to iterates properties of an object. Let us try this, let Product = { Id: 1, Title: 'Pen', Price: 1000, sendDetail: () => { }…
-
How to seal, freeze and prevent extension of an object in JavaScript
Read full article on the Infragistics blog In modern JavaScript, objects are integral, and having a strong understanding of topics surrounding objects is necessary for writing better JavaScript. You can create an object in four ways in JavaScript. Read about them in greater detail here. Once you know how to create an object, you may…
-
Four Ways to Create Objects in JavaScript
In JavaScript, there are four methods to use to create an object: Object literals New operator or constructor Object.create method Class In this post, we will learn each of these methods. Object literals An object literal, also called an object initializer, is a comma-separated set of paired names and values. You can create an object…
-
How to print or enumerate properties of a JavaScript object?
I usually come across the following requirements, How to print name of all the properties of an object? How to print only the methods of an object? How to print even non-enumerable properties of an object? In this post, we will explore all the options to iterate and print properties of a JavaScript object. Let…
-
Simplifying Objects, Inheritance and prototype in JavaScript
This blog post explains about Objects, Inheritance and Prototype in JavaScript