vendredi 29 mai 2015

How to check if variable is an empty Object {}? [duplicate]

This question already has an answer here:

enter image description here

function setUserName() {
    var usr = AuthService.getUser();

    if (typeof usr !== "undefined") {
        vs.user = usr;
    } else {
        vs.user = 'Settings';
    }

    // if (usr.username === undefined && usr.username === null) {
    //     vs.user = 'Settings';
    // } else {
    //     vs.user = usr;
    // }

    console.log(usr);
}

In my code above usr is currently an empty Object {} how should this check be written so that it skips down to the else and set vs.user to 'Settings'?

Aucun commentaire:

Enregistrer un commentaire