I think it would be easiest to explain what I'm asking with an example.
function getLastNode() {
let current = this.head;
if (current == null) {
// Here, we could either return current, or return null
}
while (current.getNext() != null) {
current = current.getNext();
}
return current;
}
In the beginning of the function, in the if statement, we have a choice to either write the return statement as return current
or return null
. In situations like this you could choose either option since they are equivalent.
To avoid this question being considered primarily opinion-based, I want to know if there is any type of convention for this. Is there a standard, convention, or style guide that specifies a standard practice?
Thanks!