jeudi 29 juin 2017

Are these JS conditional statements functionally equivalent?

Regarding conditional if/else statements, are the following examples functionally equivalent?

function isEntering() {
    if (this.stage = 'entering') {
        return true;
    } else {
        return false;
}

function isEntering() {
    if (this.stage = 'entering') {
        return true;
    } return false;
}

function isEntering() {
    if (this.stage = 'entering') {
        return true;
    } 
}

isEntering = (this.stage === 'entering') ? true : false;

If so, I'd use the most terse of the options. But only if the three are functionally equivalent.

Aucun commentaire:

Enregistrer un commentaire