How to always return a default value for an object property in javascript?

Standard

Hi Guys,

Do you have a need where you want to return something as a default value if your JS object don’t have that property?

Let’s come to our problem.

Lets take an object (kind of a key value configuration object) which is coming from server and we need to make some very important decision based on this data.

var electricalConfig = {
  isLightOn: true,
  isBoardSmart: false,
  noOfSwitch: 10,
  noOfSockets: 3,
  isConnected: true
};

Continue reading