JavaScript'te Genel Kısa Form Kontrol
Kısa form kontrol, diğer veri türleri için de
çalışır. Bu durumda, bu veriler önce boolean
türüne dönüştürülür, ardından true ile
karşılaştırılır. Örneğe bakın:
let test = 3;
if (test) {
console.log('+++'); // bu çalışır
} else {
console.log('---');
}
Aslında verilen kod aşağıdakine eşdeğerdir:
let test = 3;
if (Boolean(test) === true) {
console.log('+++');
} else {
console.log('---');
}
Kodu çalıştırmadan, konsola ne yazdırılacağını belirleyin:
let test = 3;
if (test) {
console.log('+++');
} else {
console.log('---');
}
Kodu çalıştırmadan, konsola ne yazdırılacağını belirleyin:
let test = 'abc';
if (test) {
console.log('+++');
} else {
console.log('---');
}
Kodu çalıştırmadan, konsola ne yazdırılacağını belirleyin:
let test = '';
if (test) {
console.log('+++');
} else {
console.log('---');
}
Kodu çalıştırmadan, konsola ne yazdırılacağını belirleyin:
let test = 3 * 'abc';
if (test) {
console.log('+++');
} else {
console.log('---');
}
Kodu çalıştırmadan, konsola ne yazdırılacağını belirleyin:
let test = null;
if (test) {
console.log('+++');
} else {
console.log('---');
}
Kodu çalıştırmadan, konsola ne yazdırılacağını belirleyin:
let test = false;
if (test) {
console.log('+++');
} else {
console.log('---');
}
Kodu çalıştırmadan, konsola ne yazdırılacağını belirleyin:
let test;
if (test) {
console.log('+++');
} else {
console.log('---');
}
Kodu çalıştırmadan, konsola ne yazdırılacağını belirleyin:
let test = 0;
if (test) {
console.log('+++');
} else {
console.log('---');
}
Kodu çalıştırmadan, konsola ne yazdırılacağını belirleyin:
let test = '0';
if (test) {
console.log('+++');
} else {
console.log('---');
}
Kodu çalıştırmadan, konsola ne yazdırılacağını belirleyin:
let test = -1;
if (test) {
console.log('+++');
} else {
console.log('---');
}