Forma e shkurtuar e kontrollit për vlerën false në JavaScript
Le të themi se tani duam të kontrollojmë vlerën e një ndryshoreje për false. Kjo mund të bëhet në mënyrën e mëposhtme:
let test = true;
if (test === false) {
console.log('+++');
} else {
console.log('---');
}
Mund të shkruhet gjithashtu kod ekuivalent me mohim:
let test = true;
if (test !== true) {
console.log('+++');
} else {
console.log('---');
}
Kodi i dhënë mund të rishkruhet në formë të shkurtuar si më poshtë:
let test = true;
if (!test) {
console.log('+++');
} else {
console.log('---');
}
Rishkruani kodin e mëposhtëm duke përdorur formën e shkurtuar:
let test = true;
if (test == false) {
console.log('+++');
} else {
console.log('---');
}
Rishkruani kodin e mëposhtëm duke përdorur formën e shkurtuar:
let test = true;
if (test != true) {
console.log('+++');
} else {
console.log('---');
}
Rishkruani kodin e mëposhtëm duke përdorur formën e shkurtuar:
let test = true;
if (test != false) {
console.log('+++');
} else {
console.log('---');
}