ﺎﯾ true :ﺪﻫﺩ ﯽﻣ ﻥﺎﺸﻧ ﺍﺭ ﺭﺍﺪﻘﻣ ﻭﺩ ﺯﺍ ﯽﮑﯾ ﯽﻟﻮﺑ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﮏﯾ
ﺪﺷﺎﺑ ﻪﺘﺷﺍﺩ ﻩﺩﺍﺩ ﻉﻮﻧ ﮏﯾ ﺪﻧﺍﻮﺗ ﯽﻣ ﻂﻘﻓ ﻪﮐ ﺪﯾﺭﺍﺩ ﺯﺎﯿﻧ ﻩﺩﺍﺩ ﻉﻮﻧ ﮏﯾ ﻪﺑ ،ﯽﺴﯾﻮﻧ ﻪﻣﺎﻧﺮﺑ ﺭﺩ ،ﺕﺎ
ﺮﯿﺧ ﻪﻠﺑ
ﺵﻮﻣﺎﺧ ﻦﺷﻭﺭ
ﻂﻠﻏ ﺖﺳﺭﺩ
ﺪﻧﺍﻮﺗ ﯽﻣ ﻂﻘﻓ .ﺖﺳﺍ Boolean ﻩﺩﺍﺩ ﻉﻮﻧ ﮏﯾ ﯼﺍﺭﺍﺩ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ،ﺭﺎﮐ ﻦﯾﺍ ﯼﺍ
(ﺮﯿﻐﺘﻣ ﮏﯾ ﺎﯾ) ﺕﺭﺎﺒﻋ ﮏﯾ ﺪﯿﻤﻬﻔﺑ ﺎﺗ ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ :ﺮﺗ ﻩﺩﺎﺳ ﯽﺘﺣ ﺎﯾ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ .ﺪﻫﺩ ﯽﻣ ﻪﺴﯾﺎﻘﻣ ﯼﺎﻫﺮﮕﻠﻤﻋ ﺯﺍ ﯽﻠﮐ ﯼﺎﻤﻧ ﮏﯾ JS Comparisons ﻞﺼﻓ .ﺪﻫﺩ ﯽﻣ ﻪﺋﺍﺭﺍ ﯽﻃﺮﺷ ﺕﺍﺭﺎﺒﻋ ﺯﺍ ﯽﻠﮐ ﯼﺎﻤﻧ ﮏﯾ JS Conditions ﻞﺼﻓ :ﺖﺳﺍ ﻩﺪﺷ ﻩﺩﺭﻭﺁ ﻪﻧﻮﻤﻧ ﺪﻨﭼ ﺎﺠﻨﯾﺍ ﺭﺩ ﺕﺎﺤﯿﺿﻮﺗ: ﺎﺑ ﺮﺑﺍﺮﺑ ﻝﺎﺜﻣ: ﺕﺎﺤﯿﺿﻮﺗ: ﺯﺍ ﺮﺘﺸﯿﺑ ﻝﺎﺜﻣ: ﺕﺎﺤﯿﺿﻮﺗ: ﺯﺍ ﺮﺘﻤﮐ ﻝﺎﺜﻣ: .ﺖﺳﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻂﯾﺍﺮﺷ ﻭ ﺎﻫ ﻪﺴﯾﺎﻘﻣ ﻪﻤﻫ ﯼﺍﺮﺑ ﯽﯾﺎﻨﺒﻣ ﺕﺭﺎﺒﻋ ﮏﯾ ﯽﻟﻮﺑ ﺭﺍﺪﻘﻣ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ :ﺖﺳﺍ ﺖﺳﺭﺩﺎﻧ (ﺮﻔﺻ) 0 ﯽﻟﻮﺑ ﺭﺍﺪﻘﻣ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ :ﺖﺳﺍ ﺖﺳﺭﺩﺎﻧ (ﺮﻔﺻ ﯼﺎﻬﻨﻣ) -0 ﯽﻟﻮﺑ ﺭﺍﺪﻘﻣ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ :ﺖﺳﺍ ﺖﺳﺭﺩﺎﻧ (ﯽﻟﺎﺧ ﻪﺘﺷﺭ)"" ﯽﻟﻮﺑ ﺭﺍﺪﻘﻣ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ :ﺖﺳﺍ undefined false ﯽﻟﻮﺑ ﺭﺍﺪﻘﻣ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ :ﺖﺳﺍ null false ﯽﻟﻮﺑ ﺭﺍﺪﻘﻣ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ :ﺖﺳﺍ false (ﺪﯾﺩﺯ ﺱﺪﺣ ﺎﻤﺷ) false ﯽﻟﻮﺑ ﺭﺍﺪﻘﻣ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ :ﺖﺳﺍ ﺖﺳﺭﺩﺎﻧNaN ﯽﻟﻮﺑ ﺭﺍﺪﻘﻣ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ :ﺪﻧﻮﺷ ﯽﻣ ﺩﺎﺠﯾﺍ ﻆﻔﻟ ﺯﺍ ﻪﮐ ﺪﻨﺘﺴﻫ ﯽﯾﺍﺪﺘﺑﺍ ﺮﯾﺩﺎﻘﻣ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫ ﻦﯿﻟﻮﺑ ﻝﻮﻤﻌﻣ ﺭﻮﻃ ﻪﺑ :ﺪﻧﻮﺷ ﻒﯾﺮﻌﺗ .ﺪﯿﻨﮑﻧ ﺩﺎﺠﯾﺍ ﯽﻟﻮﺑ ءﺎﯿﺷﺍ .ﺪﻫﺩ ﯽﻣ ﺶﻫﺎﮐ ﺍﺭ ﺍﺮﺟﺍ ﺖﻋﺮﺳ ﻭ ﺪﻨﮐ ﯽﻣ ﻩﺪﯿﭽﯿﭘ ﺍﺭ ﺪﮐ :ﺪﻨﻨﮐ ﺩﺎﺠﯾﺍ ﯼﺍ ﻩﺮﻈﺘﻨﻣﺮﯿﻏ ﺞﯾﺎﺘﻧ ﺪﻨﻧﺍﻮﺗ ﯽﻣ ﯽﻟﻮﺑ ءﺎﯿﺷﺍ :ﺪﻨﺘﺴﻫ ﺮﺑﺍﺮﺑ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ :ﺪﻨﺘﺴﯿﻧ ﺮﺑﺍﺮﺑ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ .ﺪﯿﻨﮐ ﻪﺟﻮﺗ (x===y) ﻭ (x==y) ﻦﯿﺑ ﺕﻭﺎﻔﺗ ﻪﺑ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ .ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ falseﻪﺸﯿﻤﻫ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﺷ ﻭﺩ ﻪﺴﯾﺎﻘﻣ ﺪﯾﻭﺮﺑ ﺎﻣ Complete ﻪﺑ ،ﻞﻣﺎﮐ ﻊﺟﺮﻣ ﮏﯾ ﯼﺍﺮﺑ .ﺖﺳﺍ ﯽﻟﻮﺑ ﯼﺎﻫ ﺵﻭﺭ ﻭ ﺹﺍﻮﺧ ﻡﺎﻤﺗ ﺯﺍ ﯽﯾﺎﻫ ﻪﻧﻮﻤﻧ ﻭ ﺕﺎﺤﯿﺿﻮﺗ ﯼﻭﺎﺣ ﻊﺟﺮﻣBoolean()
ﻝﺎﺜﻣ
Boolean(10 > 9)
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Booleans</h1>
<p>Display the value of Boolean(10 > 9):</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = Boolean(10 > 9);
</script>
</body>
</html>
ﻝﺎﺜﻣ
(10 > 9)
10 > 9
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Booleans</h1>
<p>Display the value of 10 > 9:</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = 10 > 9;
</script>
</body>
</html>
ﻂﯾﺍﺮﺷ ﻭ ﺎﻫ ﻪﺴﯾﺎﻘﻣ
==
if (day == "Monday")
>
if (salary > 9000)
<
if (age < 18)
ﺖﺳﺍ ﺖﺳﺭﺩ "ﺵﺯﺭﺍ" ﮏﯾ ﺎﺑ ﯼﺰﯿﭼ ﺮﻫ
ﺎﻫ ﻝﺎﺜﻣ
100
3.14
-15
"Hello"
"false"
7 + 1 + 3.14
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Booleans</h1>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
"100 is " + Boolean(100) + "<br>" +
"3.14 is " + Boolean(3.14) + "<br>" +
"-15 is " + Boolean(-15) + "<br>" +
"Any (not empty) string is " + Boolean("Hello") + "<br>" +
"Even the string 'false' is " + Boolean('false') + "<br>" +
"Any expression (except zero) is " + Boolean(1 + 7 + 3.14);
</script>
</body>
</html>
ﺖﺳﺍ ﺖﺳﺭﺩﺎﻧ "ﺵﺯﺭﺍ" ﻥﻭﺪﺑ ﺰﯿﭼ ﻪﻤﻫ
let x = 0;
Boolean(x);
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Booleans</h1>
<p>Display the Boolean value of 0:</p>
<p id="demo"></p>
<script>
let x = 0;
document.getElementById("demo").innerHTML = Boolean(x);
</script>
</body>
</html>
let x = -0;
Boolean(x);
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Booleans</h1>
<p>Display the Boolean value of -0:</p>
<p id="demo"></p>
<script>
let x = -0;
document.getElementById("demo").innerHTML = Boolean(x);
</script>
</body>
</html>
let x = "";
Boolean(x);
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Booleans</h1>
<p>Display the Boolean value of "":</p>
<p id="demo"></p>
<script>
let x = "";
document.getElementById("demo").innerHTML = Boolean("");
</script>
</body>
</html>
let x;
Boolean(x);
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Booleans</h1>
<p>Display the Boolean value of undefined:</p>
<p id="demo"></p>
<script>
let x;
document.getElementById("demo").innerHTML = Boolean(x);
</script>
</body>
</html>
let x = null;
Boolean(x);
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Booleans</h1>
<p>Display the Boolean value of null:</p>
<p id="demo"></p>
<script>
let x = null;
document.getElementById("demo").innerHTML = Boolean(x);
</script>
</body>
</html>
let x = false;
Boolean(x);
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Booleans</h1>
<p>Display the Boolean value of false:</p>
<p id="demo"></p>
<script>
let x = false;
document.getElementById("demo").innerHTML = Boolean(x);
</script>
</body>
</html>
let x = 10 / "Hallo";
Boolean(x);
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Booleans</h1>
<p>Display the Boolean value of NaN:</p>
<p id="demo"></p>
<script>
let x = 10 / "Hello";
document.getElementById("demo").innerHTML = Boolean(x);
</script>
</body>
</html>
ﺎﯿﺷﺍ ﻥﺍﻮﻨﻋ ﻪﺑ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫ ﻦﯿﻟﻮﺑ
let x = false;
new
ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ ﺎﺑ ﯽﯾﺎﯿﺷﺍ ﻥﺍﻮﻨﻋ ﻪﺑ ﺪﻨﻧﺍﻮﺗlet y = new Boolean(false);
ﻝﺎﺜﻣ
let x = false;
let y = new Boolean(false);
//
typeof x returns boolean
//
typeof y returns object
new
let x = false;
let y = new Boolean(false);
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Booleans</h1>
<p>Booleans and Boolean objects cannot be safely compared:</p>
<p id="demo"></p>
<script>
let x = false; // x is a boolean
let y = new Boolean(false); // y is an object
document.getElementById("demo").innerHTML = (x==y);
</script>
</body>
</html>
let x = false;
let y = new Boolean(false);
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Booleans</h1>
<p>Booleans and Boolean objects cannot be safely compared:</p>
<p id="demo"></p>
<script>
let x = false; // x is a Boolean
let y = new Boolean(false); // y is an object
document.getElementById("demo").innerHTML = (x===y);
</script>
</body>
</html>
(x == y)
؟ﺖﺳﺭﺩﺎﻧ ﺎﯾ ﺖﺳﺍ ﺖﺳﺭﺩlet x = new Boolean(false);
let y = new Boolean(false);
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Booleans</h1>
<p>Booleans and Boolean objects cannot be safely compared.</p>
<p id="demo"></p>
<script>
const x = new Boolean(false);
const y = new Boolean(false);
document.getElementById("demo").innerHTML = (x==y);
</script>
</body>
</html>
(x === y)
؟ﺖﺳﺭﺩﺎﻧ ﺎﯾ ﺖﺳﺍ ﺖﺳﺭﺩlet x = new Boolean(false);
let y = new Boolean(false);
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Booleans</h1>
<p>Booleans and Boolean objects cannot be safely compared.</p>
<p id="demo"></p>
<script>
const x = new Boolean(false);
const y = new Boolean(false);
document.getElementById("demo").innerHTML = (x===y);
</script>
</body>
</html>
ﻞﻣﺎﮐ ﯽﻟﻮﺑ ﻊﺟﺮﻣ