What is the reason/benefit for writing short circuit conditional?

Viewed 31

I was searching a lot about short circuit, but I have a big doubt with this code.

const getClient = (userInfoContext) => {
  const context = userInfoContext && userInfoContext.get()
  const payload = context && context.payload && context.payload['www.payload.com']
  return payload && payload.clientId
}

I want to know what is the benefit of write the code like that instead of:

  const getClient = (userInfoContext) => {
  const context = userInfoContext.get()
  const payload = context.payload['www.payload.com']
  return payload.clientId
}
0 Answers
Related