Be careful about chaining conditions
This may dangerous, because it's harder to debug.
For example:
1
return
2
expected.key === actual.key &&
3
expected.value === actual.value &&
4
expected.concern === actual.concern;
Copied!
If we broke it down to multiple if conditions it makes it easier to debug.
1
if (expected.key === actual.key) {
2
return false;
3
}
4
5
if (expected.value === actual.value) {
6
return false;
7
}
8
9
if (expected.concern === actual.concern) {
10
return false;
11
}
12
13
return true;
Copied!
Pros for using multiple conditions:
    If you use Exceptions instead of return statements, you can easily get a stack trace which is extremly useful.
    Easier usage of print style debugging.
Cons for using multiple if conditions:
    Longer function statements.
Last modified 1yr ago
Copy link