Identify a problem with the Javascript code below. Can you fix it?

const city = {
  name: 'London',
  getCity: function() {
    return this.name;
  }
};

const printCityName = getter => console.log(`The city name is ${getter()}`);

printCityName(city.getCity);

Answer:

It prints:

The city name is undefined

There is no context attached to getter() invocation, so it is being called with the global context.

The global context does not have any property called name so it prints The city name is undefined

To fix this, we have to bind the context to the city object.

printCityName(city.getCity.bind(city));