Booleans and comparisons · القيم المنطقية والمقارنات
True and false
- A boolean is one of just two values:
trueorfalse. - Compare values to get a boolean:
===(equal),!==(not equal),<><=>=.
صحيح وخاطئ
- منطقي هو أحد قيمتين فقط:
trueأوfalse. - قارن القيم للحصول على منطقي:
===(متساوي)،!==(غير متساوي)،<><=>=.
console.log(5 === 5); // → true
console.log(3 > 7); // → false
Combine tests
&&means and — true only when both sides are true.||means or — true when at least one side is true.!means not — it flipstrueandfalse.
دمج الاختبارات
&&يعني و — صحيحة فقط عندما يكون كلا الجانبين صحيحين.||يعني أو — صحيحة عندما يكون على الأقل جانب واحد صحيحاً.!يعني ليس — تقلبtrueوfalse.
console.log(true && false); // → false
console.log(!true); // → false
Truth table — try every input · جدول الحقيقة — جرب كل مدخل
&& (and) is true only when both are true. || (or) is true when at least one is. · && (و) تكون صحيحة فقط عندما يكون كلاهما صحيحاً. || (أو) تكون صحيحة عندما يكون على الأقل واحد صحيحاً.
Watch out
- Always compare with
===, not==. The older==quietly converts types:0 == ""istrue! ===checks value and type, which is what you almost always want.
انتبه
- قارن دائماً بـ
===، وليس==. القديمان==يحولان الأنواع بهدوء:0 == ""هوtrue! ===يتحقق من القيمة و النوع، وهو ما تريده تقريباً دائماً.
Common mistakes
- Prefer
===(strict) over==, which does surprising type coercion. &&is AND,||is OR,!is NOT.
أخطاء شائعة
- يُفضّل
===(الصارم) على==، الذي يقوم بتحويل أنواع غير متوقع. &&هو AND،||هو OR،!هو NOT.
Now you try
- Each task logs
trueorfalse. - Press Check answer to test it.
الآن جرب بنفسك
- يسجل كل مهمة
trueأوfalse. - اضغط على تحقق من الإجابة لاختبارها.
Use === to log whether 10 equals 10 (it is true). · استخدم === لأخرج ما إذا كان 10 يساوي 10 (وهي true).
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.
Log whether 8 is greater than 3 (it is true). · أخرج ما إذا كان 8 أكبر من 3 (وهي true).
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.
let n = 8. Log whether n is even by testing n % 2 === 0 (it is true). · let n = 8. أخرج ما إذا كان n زوجياً باختبار n % 2 === 0 (وهي true).
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.
let age = 15. Use && to log whether the age is from 13 to 19 (a teenager) — it is true. · let age = 15. استخدم && لأخرج ما إذا كان العمر من 13 إلى 19 (مراهق) — وهي true.
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.