JavaScript-də Ümumi Qısaldılmış Yoxlama Forması
Qısaldılmış yoxlama forması
digər məlumat növləri üçün də işləyir.
Bu zaman
bu məlumatlar əvvəlcə boolean tipinə
çevrilir, sonra isə
true ilə müqayisə edilir.
Nümunəyə baxın:
let test = 3;
if (test) {
console.log('+++'); // bu işləyəcək
} else {
console.log('---');
}
Əslində təqdim olunan kod aşağıdakına ekvivalentdir:
let test = 3;
if (Boolean(test) === true) {
console.log('+++');
} else {
console.log('---');
}
Kodu işlətmədən, konsola nə çap olunacağını müəyyən edin:
let test = 3;
if (test) {
console.log('+++');
} else {
console.log('---');
}
Kodu işlətmədən, konsola nə çap olunacağını müəyyən edin:
let test = 'abc';
if (test) {
console.log('+++');
} else {
console.log('---');
}
Kodu işlətmədən, konsola nə çap olunacağını müəyyən edin:
let test = '';
if (test) {
console.log('+++');
} else {
console.log('---');
}
Kodu işlətmədən, konsola nə çap olunacağını müəyyən edin:
let test = 3 * 'abc';
if (test) {
console.log('+++');
} else {
console.log('---');
}
Kodu işlətmədən, konsola nə çap olunacağını müəyyən edin:
let test = null;
if (test) {
console.log('+++');
} else {
console.log('---');
}
Kodu işlətmədən, konsola nə çap olunacağını müəyyən edin:
let test = false;
if (test) {
console.log('+++');
} else {
console.log('---');
}
Kodu işlətmədən, konsola nə çap olunacağını müəyyən edin:
let test;
if (test) {
console.log('+++');
} else {
console.log('---');
}
Kodu işlətmədən, konsola nə çap olunacağını müəyyən edin:
let test = 0;
if (test) {
console.log('+++');
} else {
console.log('---');
}
Kodu işlətmədən, konsola nə çap olunacağını müəyyən edin:
let test = '0';
if (test) {
console.log('+++');
} else {
console.log('---');
}
Kodu işlətmədən, konsola nə çap olunacağını müəyyən edin:
let test = -1;
if (test) {
console.log('+++');
} else {
console.log('---');
}