lundi 10 juin 2019

Javascript 0 > 0?

I need help with understand what is going on...

I have this piece of code where i need chceck variable whitch can be array, integer or string... I need check if is empty. But if i get empty string my condition is true, however variable.length is 0 and condition is if variable.length > 0...

var variable = '';

console.log(typeof variable);
console.log(variable.length);

if(variable.length > 0) {
    alert('string is empty!');
} else {
    alert('string contains some characters!');
} 

Can please anybody explain this? THX.

Aucun commentaire:

Enregistrer un commentaire