Declarative code

Gaurav Dubey
Jan 27, 2021

This is post follow up of last post i.e imperative code do refer before this post

declarative code, we don’t code up all of the steps to get us to the end result. Instead, we declare what we want done, and JavaScript will take care of doing it. This explanation is a bit abstract, so let’s look at an example. Let’s take the imperative for loop code we were just looking at and refactor it to be more declarative.

const people = ['Amanda', 'Farrin', 'Geoff', 'Karen', 'Richard', 'Tyler']const excitedPeople = people.map(name => name + '!');

end result is:

["Amanda!", "Farrin!", "Geoff!", "Karen!", "Richard!", "Tyler!"]

this all about declarative coding this concept is helpful if you are in react development pathway.

Thanks for reading .

--

--