Category: JavaScript
-
How to make a property non-enumerable in JavaScript?
By default, all the properties of JavaScript objects are enumerable. That means you can enumerate them in a for loop or read them using the Object.values(). Let us consider an object Dog as shown below, You can enumerate all properties and read their values using the for loop or Object.values() method as shown below, Now […]
-
How to merge arrays using spread operator in JavaScript?
Have you come across a requirement to merge two or more arrays into another array? Let us say, you have two arrays as shown below, You need to merge them in another array with optional extra elements in the resultant array. JavaScript array spread operator makes it very simple to merge arrays. You can merge […]
-
How to create Private Properties in JavaScript.
We don’t have Access Modifiers in JavaScript, and all properties of an object are public, which means you can read and modify them outside the object. But what if you have a requirement to create private properties? Consider Product object as mentioned below, By default, JavaScript allows you to read and modify all the properties. […]
-
Explain Object.keys in JavaScript
Enumerating through the properties of a JavaScript object is a persistent requirement. Hence it becomes a popular question in a JavaScript interview. Any good JavaScript developer must know about various available options. Note: You can find a video tutorial on the same at the end of the article. To start with considering the Dog object […]
-
Five Things about JavaScript delete operator
A better understanding of delete operator is necessary for JavaScript developers. As the name suggests, the delete operator deletes properties from the object. You can delete a property as shown below: It returns true on successful deletion. However, in some cases, it may return true even if it does not delete a property. In this […]
-
All about NaN in JavaScript
In JavaScript, NaN is one of the most confusing concepts; hence, it is often asked in the interview. You may have come across questions such as, What is NaN What is the type of NaN How to check for the NaN What is the difference between isNaN() and Number.isNaN() In this post, let us learn […]
-
Simplifying Maps in the JavaScript
Maps is a data structure, which stores the key/value pair in an ordered way. Since the inception of the JavaScript, objects are primarily used for the map. Consider the below code listing: To store two key/value pairs, we have created an object foo and using the keys such as id and color to retrieve […]
-
Why you need Proxy objects in JavaScript
JavaScript is not truly Object Oriented language, hence implementing requirements as stated below could be challenging. For example, Throw an error if the setting value of a property does not satisfy a particular condition If the property does not exist on set some default value instead of undefined If the property does not exist on […]
-
Step by Step implementing Two-Way Data Binding in Vanilla JavaScript
Data Binding is one of the most important features of all the frameworks. It ensures that the data model and the views are in sync with each other. It is very fundamental feature of any MV* frameworks such that Model-View-Controller, Mode-View-ViewModel, and Model-View-Presenter, etc. Popular JavaScript based frameworks such that React, Angular have their way […]
-
Type of Undeclared Variable in JavaScript: What is it?
Have you ever thought, what is type of undeclared variable in JavaScript? I know, the first thing that might come to mind is: how can an undeclared variable have a type? Yes, in JavaScript it is possible. To understand it, let us start with understanding types in JavaScript. There are seven built in types in JavaScript. […]