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. · && (AND) הוא נכון רק כאשר שניהם נכונים. || (OR) הוא נכון כאשר לפחות אחד מהם נכון.
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. · לחץ על הרץ כדי לראות את התוצא כאן.