How to use JavaScript Computed Properties

Alex Ritzcovan
DailyJS
Published in
3 min readJan 28, 2020

--

Photo by Max Nelson on Unsplash

Computed property names have been around since ECMAScript 2015 but I don’t see them being used a lot in my travels. Computed properties allow you to put an expression in brackets []. That expression is evaluated and used as the property name on the object in question.

Why should you care?

Computed properties can be especially useful when dealing with event handlers on a page. They allow you to define a single function that can handle all changes on a form by the type of input element in an elegant manner. Before we look at the code, let’s see the form in action.

Super Exciting!

We’re clearly on our way to becoming the next Amazon. 😃

Let’s see the code that powers this beast.

Here is our basic HTML form markup. Note that we have specified the name attribute on each of the inputs. We will be using this later on.

--

--

Alex Ritzcovan
DailyJS

Tech guy living in Sunny South Florida. Always learning and sharing what I learn with others.