Wa maxey Truthy and Falsy ? Micnaha guud waxa uu yahay Truthy waa value jiro ama run ah. Falsy waa value aana jirin ama run aaana eheen. Waxaa jiro 5 nooc oo Falsy values ey u taqaano javaScript, waxeyna kala yihiin 0, “”, undefined, null iyo NaN. Wixii aana intaan eheen odhan javaScript waxey u taqaana Truthy values.
Waxa jiro Object globall ah oo aad ku ogaan karto hadii value_ga uu yahay true ama false.
Boolean Object wuxu kuso celinaya true hadii value ga uu yahay Truthy hadii kalane Falsy ayu kuso celinaya.
console.log(Boolean(0)); //false
console.log(Boolean(1)); //true
console.log(Boolean(undefined)); //false
Aqriste inta badan Truthy and Falsy waxey dhacaan marki javaScript ey sameyso Type-coercion.
Aqriste hadii aad isticmaaleysid logical operators ama if else javaScript waxey sameeneysa type-coercion.
Tusaalahan hoose waxaan isla arki doona in qofkan u heysto lacag iyo inkale, sidokale waxaan isla arki doonaa mesha uu ka dhacayo type-coercion ka.
const money = 0;
if (money) {
console.log("Waxaad heysataa lacag.");
} else {
console.log("Wax lacag ah ma heysatid."); // ouput will be this.
}
variable ka money waxaa uu inoo hayaa value 0, oo la micno ah in qofkan uusan heysan wax lacag ah.
Line_ka ku xigo waxaan checking/hubin ku sameeney in qofkan lacag uu heysto iyo inkale.
javaScript waxey so qabaneysa variable_ka money qiimaha ku jiro markii ey aragto in 0 uu yahay waxey u arkeysa Falsy value inu yahay kadib waxey u gudbeysa else statement.
if(money) meshan weeyo mesha uu ka dhacayo type-coercion ka. Variable money ayey u badaleysa to Boolean si false ama true ey usoo baxdo.
Aqriste waxaan rajeenaya inaad si fcn u fahantey Tuthy iyo Falsy.