Javascript condition & 0 value


Recently, I had to debug an error caused by a Javascript condition:

  if (utcOffset) {
// do fancy things
}

The problem with utcOffset param is that i can be a 0 value.

Unfortunatley, there is no better way to solve this than using the following condition:

  if (utcOffset !== undefined && utcOffset !== null) {
// do fancy things
}

This way a 0 value will be passing the condition.

Related Posts

Moment.js - Reduce Webpack Bundle Size

How to reduce the packaged webpack bundle size of moment.js

Scroll Bottom with React

Scrolling to bottom with React using the Lifecycle Methods and Dom Reference