I have a program that calls a back-end service and collects a response. It is collected as follows. We destructure the response object and get the Error
and Data
.
const { data, error } = response;
If there is no error, the Error
object becomes null. Consider the following two options.
Option One:
if (!error) {
// handle error
}
Option Two:
if (error !== null) {
// handle error
}
In Option One, As per this answer, the following conditions are checked.
- undefined: if the value is not defined and it's undefined
- null: if it's null, for example, if a DOM element not exists...
- empty string: ''
- 0: number zero
- NaN: not a number
- false
Is there an order of execution when we call Option 1? How does the internal condition checking happen in Option 1? Based on this, will there be a performance impact (in a granular level), if we use Option 1 instead of Option 2?