Me and my team are developing a Phonegap app, and are encountering some issues. One of our functions looks like this:
var email = localStorage.getItem("email");
if (email != "" && email.type != undefined) {
//Do stuffs
} else {
//Do other stuffs
};
But, despite the local storage item 'email' being set to my email, it still executes the contents of the else statement, not the main if block. Maybe the answer is right under our noses, we just don't know (its 6 am here, very tired), so any help is appreciated.
This is because the email
will always return null
if not set. I recommend just doing:
var email = localStorage.getItem("email");
if (email !== null) {
//Do stuffs
} else {
//Do other stuffs
};