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

Arrow functions in Javascript

Standard

Let’s meet our buddy called arrow function. What are they?

Arrow functions are short hands for writing a function which doesn’t need a name and works in lexical scopes.

As per mozilla:

An arrow function expression has a shorter syntax compared to function expressions and lexically binds the this value (does not bind its own this, arguments, super, or new.target). Arrow functions are always anonymous. These function expressions are best suited for non-method functions and they can not be used as constructors.

Continue reading