 Hello, I'm Rebecca Murphy and I'm a developer at Boku and in this video I want to talk about how you can use objects to reduce the repetitiveness of your code Let's take a look at an example of some repetitive code that we can clean up using an object So this is a simple function and what it does is it uses a selected location Probably selected from a select drop-down or something like that It uses a selected location and then sets a maps center and sets a maps zoom level Depending on which location was chosen And we can see when we look at this that this is some pretty repetitive code And it's basically three if statements that do something slightly different depending on which location was chosen But the basic contents of those if statements doesn't really change all that changes is the latitude and longitude For the location and of course the zoom level So we can clean up this Function by using an object. Let's take a look at what that would look like We'll recreate our function Down here And of course the first thing we want to do we are still going to need that selected Which location was selected? So we'll grab that The next thing we're going to do is create a locations object And that locations object is going to have three properties on it It's going to have Ireland as a property and We'll assign that an object. It's going to have Claire as a property and assign that an object It's going to have Dublin as a property and again, we'll assign that an object and Inside each of these per location objects. What we're going to do is enter the latitude the longitude And the zoom level for the location And so we'll grab that Copy it down to here and to here and Then we'll take the data from up above and move it into These objects So now we've created a locations object that contains all of that information that changes Inside of those if statements and all we have left is what doesn't change inside of those if statements So let's grab the content of one of those if statements and we'll pull it down to here and adapt it to what it needs to be now that we have Removed all of that location information out to the out to the locations object So the first thing we need to do is it actually get you know Assuming that someone has chosen Ireland as the location in the in the select menu We need to actually get this object So the way that we'll do that is say our location equals locations and then we'll look up the selected location In that locations object so we'll do that using bracket notation and This will this will let us look up Ireland or Claire or Dublin Next we'll say that var Center equals New Google Maps lat long and then we'll get the latitude and longitude From that location object So again if the user had chosen Ireland then location dot lat at this point points to this value And location dot long points to this value So now we want to set the center on that new center and finally we want to set the zoom to The zoom property of that location object. So that in this case would be six if a user had chosen Ireland This New function is it has the same functionality as the function up here But it has a few benefits number one We aren't repeating the same code over and over and over again And that has payoffs as far as maintainability and as far as your sanity Especially if you ever have to change that code, you don't want to be changing it in three places The other benefit that we got here is that it becomes really easy to add a new location We don't have to write a whole new if statement in order to support another location We just have to add another property to this locations object and pass in that that information for that location and You can even imagine a case where you might get this locations object from the server So it doesn't have to be hard coded into your JavaScript anymore. It's something that could change So you get a lot more flexibility by using an object for this purpose In addition to the benefits that you get just from having more dry. Don't repeat yourself code Thanks for watching I'm Rebecca Murphy and this was a bokeh training production You