ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺩﺍﺪﻋﺍ


فهرست مطالب

    نمایش فهرست مطالب


.ﺩﺭﺍﺩ ﺩﺪﻋ ﻉﻮﻧ ﮏﯾ ﻂﻘﻓ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ


ﻝﺎﺜﻣ

let x = 3.14;    // A number with decimals
let y = 3;       // A number without decimals

ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ

:ﺖﺷﻮﻧ (ﺶﯾﺎﻤﻧ) ﯽﻤﻠﻋ ﺩﺎﻤﻧ ﺎﺑ ﻥﺍﻮﺗ ﯽﻣ ﺍﺭ ﮏﭼﻮﮐ ﺭﺎﯿﺴﺑ ﺎﯾ ﮒﺭﺰﺑ ﺭﺎﯿﺴﺑ ﺩﺍﺪﻋﺍ

ﻝﺎﺜﻣ

let x = 123e5;    // 12300000
let y = 123e-5;   // 0.00123

ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ


ﺪﻨﺘﺴﻫ ﺭﻭﺎﻨﺷ ﯽﺘﯿﺑ 64 ﻪﺸﯿﻤﻫ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺩﺍﺪﻋﺍ

،ﺮﮕﯾﺩ ﯽﺴﯾﻮﻧ ﻪﻣﺎﻧﺮﺑ ﯼﺎﻫ ﻥﺎﺑﺯ ﺯﺍ ﯼﺭﺎﯿﺴﺑ ﻑﻼﺧﺮﺑ

ﺪﻧﻮﺷ ﯽﻣ ﻩﺮﯿﺧﺫ ﻒﻋﺎﻀﻣ ﺖﻗﺩ ﺎﺑ ﺭﻭﺎﻨﺷ ﺰﯿﻤﻣ ﺕﺭﻮﺻ ﻪﺑ ﻪﺸﯿﻤﻫ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺩﺍﺪﻋﺍ

Value (aka Fraction/Mantissa) Exponent Sign
52 bits (0 - 51)  11 bits (52 - 62) 1 bit (63)

ﺢﯿﺤﺻ ﺩﺪﻋ ﺖﻗﺩ

.ﺪﻨﺘﺴﻫ ﻖﯿﻗﺩ ﻢﻗﺭ 15 ﺎﺗ (ﻥﺍﻮﺗ ﺩﺎﻤﻧ ﺎﯾ ﻪﻄﻘﻧ ﻥﻭﺪﺑ ﺩﺍﺪﻋﺍ) ﺢﯿﺤﺻ ﺩﺍﺪﻋﺍ

ﻝﺎﺜﻣ

let x = 999999999999999;   // x will be 999999999999999
let y = 9999999999999999;  // y will be 10000000000000000

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Numbers</h1>
<h2>Integer Precision</h2>

<p>Integers (numbers without a period or exponent notation) are accurate up to 15 digits:</p>

<p id="demo"></p>

<script>
let x = 999999999999999;
let y = 9999999999999999;
document.getElementById("demo").innerHTML = x + "<br>" + y;
</script>

</body>
</html>


.ﺖﺳﺍ 17 ﺭﺎﺸﻋﺍ ﺩﺍﺪﻌﺗ ﺮﺜﮐﺍﺪﺣ

ﺭﻭﺎﻨﺷ ﺖﻗﺩ

:ﺖﺴﯿﻧ ﻖﯿﻗﺩ ٪100 ﻪﺸﯿﻤﻫ ﺭﻭﺎﻨﺷ ﺰﯿﻤﻣ ﺕﺎﺒﺳﺎﺤﻣ

let x = 0.2 + 0.1;

ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ

:ﺪﻨﮐ ﯽﻣ ﮏﻤﮐ ﻢﯿﺴﻘﺗ ﻭ ﺏﺮﺿ ﻪﺑ ،ﻻﺎﺑ ﻞﮑﺸﻣ ﻞﺣ ﯼﺍﺮﺑ

let x = (0.2 * 10 + 0.1 * 10) / 10;

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Numbers</h2>

<p>Floating point arithmetic is not always 100% accurate:</p>
<p id="demo1"></p>

<p>But it helps to multiply and divide:</p>

<p id="demo2"></p>

<script>
let x = 0.2 + 0.1;
document.getElementById("demo1").innerHTML = "0.2 + 0.1 = " + x;
let y = (0.2*10 + 0.1*10) / 10;
document.getElementById("demo2").innerHTML = "0.2 + 0.1 = " + y;
</script>

</body>
</html>




ﺎﻫ ﻪﺘﺷﺭ ﻭ ﺩﺍﺪﻋﺍ ﻥﺩﺮﮐ ﻪﻓﺎﺿﺍ

!!ﺭﺍﺪﺸﻫ

.ﺪﻨﮐ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﻕﺎﺤﻟﺍ ﯼﺍﺮﺑ ﻢﻫ ﻭ ﻊﻤﺟ ﯼﺍﺮﺑ ﻢﻫ + ﺮﮕﻠﻤﻋ ﺯﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ

.ﺪﻧﺍ ﻪﺘﺳﻮﯿﭘ ﻢﻫ ﻪﺑ ﺎﻫ ﻪﺘﺷﺭ .ﺪﻧﻮﺷ ﯽﻣ ﻪﻓﺎﺿﺍ ﺩﺍﺪﻋﺍ

:ﺩﻮﺑ ﺪﻫﺍﻮﺧ ﺩﺪﻋ ﮏﯾ ﻪﺠﯿﺘﻧ ،ﺪﯿﻨﮐ ﻪﻓﺎﺿﺍ ﺍﺭ ﺩﺪﻋ ﻭﺩ ﺮﮔﺍ

ﻝﺎﺜﻣ

let x = 10;
let y = 20;
let z = x + y;

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Numbers</h2>

<p>If you add two numbers, the result will be a number:</p>

<p id="demo"></p>

<script>
let x = 10;
let y = 20;
let z = x + y;
document.getElementById("demo").innerHTML = z;
</script>

</body>
</html>


:ﺩﻮﺑ ﺪﻫﺍﻮﺧ ﻪﺘﺷﺭ ﻕﺎﺤﻟﺍ ﮏﯾ ﻪﺠﯿﺘﻧ ،ﺪﯿﻨﮐ ﻪﻓﺎﺿﺍ ﻪﺘﺷﺭ ﻭﺩ ﺮﮔﺍ

ﻝﺎﺜﻣ

let x = "10";
let y = "20";
let z = x + y;

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Numbers</h2>

<p>If you add two numeric strings, the result will be a concatenated string:</p>

<p id="demo"></p>

<script>
let x = "10";
let y = "20";
let z = x + y;
document.getElementById("demo").innerHTML = z;
</script>

</body>
</html>


:ﺩﻮﺑ ﺪﻫﺍﻮﺧ ﻪﺘﺷﺭ ﻕﺎﺤﻟﺍ ﮏﯾ ﻪﺠﯿﺘﻧ ،ﺪﯿﻨﮐ ﻪﻓﺎﺿﺍ ﻪﺘﺷﺭ ﮏﯾ ﻭ ﺩﺪﻋ ﮏﯾ ﺮﮔﺍ

ﻝﺎﺜﻣ

let x = 10;
let y = "20";
let z = x + y;

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Numbers</h2>

<p>If you add a number and a numeric string, the result will be a concatenated string:</p>

<p id="demo"></p>

<script>
let x = 10;
let y = "20";
let z = x + y;
document.getElementById("demo").innerHTML = z;
</script>

</body>
</html>


:ﺩﻮﺑ ﺪﻫﺍﻮﺧ ﻪﺘﺷﺭ ﻕﺎﺤﻟﺍ ﮏﯾ ﻪﺠﯿﺘﻧ ،ﺪﯿﻨﮐ ﻪﻓﺎﺿﺍ ﺩﺪﻋ ﮏﯾ ﻭ ﻪﺘﺷﺭ ﮏﯾ ﺮﮔﺍ

ﻝﺎﺜﻣ

let x = "10";
let y = 20;
let z = x + y;

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Numbers</h2>

<p>If you add a numeric string and a number, the result will be a concatenated string:</p>

<p id="demo"></p>

<script>
let x = "10";
let y = 20;
document.getElementById("demo").innerHTML = "The result is: " + x + y;
</script>

</body>
</html>


:ﺪﺷﺎﺑ 30 ﻪﺠﯿﺘﻧ ﻦﯾﺍ ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﺭﺎﻈﺘﻧﺍ ﻪﮐ ﺖﺳﺍ ﻦﯾﺍ ﺞﯾﺍﺭ ﻩﺎﺒﺘﺷﺍ ﮏﯾ

ﻝﺎﺜﻣ

let x = 10;
let y = 20;
let z = "The result is: " + x + y;

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Numbers</h2>

<p>A common mistake is to expect this result to be 30:</p>

<p id="demo"></p>

<script>
var x = 10;
var y = 20;
document.getElementById("demo").innerHTML =
"The result is: " + x + y;
</script>

</body>
</html>


:ﺪﺷﺎﺑ 102030 ﻪﺠﯿﺘﻧ ﻦﯾﺍ ﻢﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﺭﺎﻈﺘﻧﺍ ﻪﮐ ﺖﺳﺍ ﻦﯾﺍ ﺞﯾﺍﺭ ﻩﺎﺒﺘﺷﺍ ﮏﯾ

ﻝﺎﺜﻣ

let x = 10;
let y = 20;
let z = "30";
let result = x + y + z;

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Numbers</h2>

<p>A common mistake is to expect this result to be 102030:</p>

<p id="demo"></p>

<script>
let x = 10;
let y = 20;
let z = "30";
let result = x + y + z;
document.getElementById("demo").innerHTML = result;
</script>

</body>
</html>


.ﺪﻨﮐ ﯽﻣ ﺭﺎﮐ ﺖﺳﺍﺭ ﻪﺑ ﭗﭼ ﺯﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺮﺴﻔﻣ

.ﺪﻨﺘﺴﻫ ﺩﺪﻋ ﻭﺩ ﺮﻫ y ﻭ x ﺍﺮﯾﺯ ﺩﻮﺷ ﯽﻣ ﻪﻓﺎﺿﺍ 20 + 10 ﻝﻭﺍ

.ﺖﺳﺍ ﻪﺘﺷﺭ ﮏﯾ z ﺍﺮﯾﺯ ﺩﻮﺷ ﯽﻣ ﻞﺼﺘﻣ ﻢﻫ ﻪﺑ "30" + 30 ﺲﭙﺳ


ﯼﺩﺪﻋ ﯼﺎﻫ ﻪﺘﺷﺭ

:ﺪﻨﺷﺎﺑ ﻪﺘﺷﺍﺩ ﯼﺩﺪﻋ ﯼﺍﻮﺘﺤﻣ ﺪﻨﻧﺍﻮﺗ ﯽﻣ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫ ﻪﺘﺷﺭ

let x = 100;         // x is a number

let y = "100";       // y is a 
string

:ﺪﻨﮐ ﺩﺍﺪﻋﺍ ﻪﺑ ﻞﯾﺪﺒﺗ ﯼﺩﺪﻋ ﯼﺎﻫ ﺕﺎﯿﻠﻤﻋ ﻡﺎﻤﺗ ﺭﺩ ﺍﺭ ﺎﻫ ﻪﺘﺷﺭ ﺪﻨﮐ ﯽﻣ ﯽﻌﺳ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ

:ﺩﺮﮐ ﺪﻫﺍﻮﺧ ﺭﺎﮐ ﻦﯾﺍ

let x = "100";
let y = "10";
let z = x / y;

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Numbers</h2>

<p>JavaScript will try to convert strings to numbers when dividing:</p>

<p id="demo"></p>

<script>
let x = "100";
let y = "10";
let z = x / y;   
document.getElementById("demo").innerHTML = z;
</script>

</body>
</html>

:ﺩﺮﮐ ﺪﻫﺍﻮﺧ ﺭﺎﮐ ﺰﯿﻧ ﻦﯾﺍ

let x = "100";
let y = "10";
let z = x * y;

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Numbers</h2>

<p>JavaScript will try to convert strings to numbers when multiplying:</p>

<p id="demo"></p>

<script>
let x = "100";
let y = "10";
let z = x * y;   
document.getElementById("demo").innerHTML = z;
</script>

</body>
</html>

:ﺩﺮﮐ ﺪﻫﺍﻮﺧ ﺭﺎﮐ ﻦﯾﺍ ﻭ

let x = "100";
let y = "10";
let z = x - y;

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Numbers</h2>

<p>JavaScript will try to convert strings to numbers when subtracting:</p>

<p id="demo"></p>

<script>
let x = "100";
let y = "10";
let z = x - y;   
document.getElementById("demo").innerHTML = z;
</script>

</body>
</html>

:ﺩﺮﮐ ﺪﻫﺍﻮﺨﻧ ﺭﺎﮐ ﻦﯾﺍ ﺎﻣﺍ

let x = "100";
let y = "10";
let z = x + y;

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Numbers</h2>

<p>JavaScript will NOT convert strings to numbers when adding:</p>

<p id="demo"></p>

<script>
let x = "100";
let y = "10";
let z = x + y;   
document.getElementById("demo").innerHTML = z;
</script>

</body>
</html>

.ﺪﻨﮐ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﺎﻫ ﻪﺘﺷﺭ ﻦﺘﺳﻮﯿﭘ ﻢﻫ ﻪﺑ ﯼﺍﺮﺑ + ﺮﮕﻠﻤﻋ ﺯﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺮﺧﺁ ﻝﺎﺜﻣ ﺭﺩ


NaN - ﺖﺴﯿﻧ ﺩﺪﻋ ﮏﯾ

NaN ﺖﺴﯿﻧ ﯽﻧﻮﻧﺎﻗ ﻩﺭﺎﻤﺷ ﮏﯾ ﺩﺪﻋ ﮏﯾ ﺪﻫﺩ ﯽﻣ ﻥﺎﺸﻧ ﻪﮐ ﺖﺳﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻩﺪﺷ ﻭﺭﺯﺭ ﻪﻤﻠﮐ ﮏﯾ.

ﮏﯾ ﻪﻧ) ﺩﻮﺷ ﯽﻣ NaN ﻪﺑ ﺮﺠﻨﻣ ﯼﺩﺪﻋ ﺮﯿﻏ ﻪﺘﺷﺭ ﮏﯾ ﺎﺑ ﺕﺎﺒﺳﺎﺤﻣ ﻡﺎﺠﻧﺍ ﯼﺍﺮﺑ ﺵﻼﺗ

ﻝﺎﺜﻣ

let x = 100 / "Apple";

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Numbers</h2>

<p>A number divided by a non-numeric string becomes NaN (Not a Number):</p>

<p id="demo"></p>

<script>
document.getElementById("demo").innerHTML = 100 / "Apple";
</script>

</body>
</html>

ﺩﻮﺑ ﺪﻫﺍﻮﺧ a ﻪﺠﯿﺘﻧ ،ﺪﺷﺎﺑ ﯼﺩﺪﻋ ﻪﺘﺷﺭ ﺮﮔﺍ ،ﻝﺎﺣ ﻦﯾﺍ ﺎﺑ

ﻝﺎﺜﻣ

let x = 100 / "10";

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Numbers</h2>

<p>A number divided by a numeric string becomes a number:</p>

<p id="demo"></p>

<script>
document.getElementById("demo").innerHTML = 100 / "10";
</script>

</body>
</html>

ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ isNaN() ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﻧﺎﻬﺟ ﻊﺑﺎﺗ ﺯﺍ ﺪﯿﻧﺍﻮﺗ ﯽﻣ

ﻝﺎﺜﻣ

let x = 100 / "Apple";
isNaN(x);

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Numbers</h2>

<p>You can use the global JavaScript function isNaN() to find out if a value is not a number:</p>

<p id="demo"></p>

<script>
let x = 100 / "Apple";
document.getElementById("demo").innerHTML = isNaN(x);
</script>

</body>
</html>

:ﺩﻮﺑ ﺪﻫﺍﻮﺧ NaN ﺰﯿﻧ ﻪﺠﯿﺘﻧ ،ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﯽﺿﺎﯾﺭ ﺕﺎﯿﻠﻤﻋ ﮏﯾ ﺭﺩ

ﻝﺎﺜﻣ

let x = NaN;
let y = 5;
let z = x + y;

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Numbers</h2>

<p>If you use NaN in a mathematical operation, the result will also be NaN:</p>

<p id="demo"></p>

<script>
let x = NaN;
let y = 5;
document.getElementById("demo").innerHTML = x + y;
</script>

</body>
</html>

:ﺪﺷﺎﺑ NaN5 ﺪﻨﻧﺎﻣ ﯽﻗﺎﺤﻟﺍ ﺖﺳﺍ ﻦﮑﻤﻣ ﻪﺠﯿﺘﻧ ﺎﯾ

ﻝﺎﺜﻣ

let x = NaN;
let y = "5";
let z = x + y;

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Numbers</h2>

<p>If you use NaN in a mathematical operation, the result can be a concatenation:</p>

<p id="demo"></p>

<script>
let x = NaN;
let y = "5";
document.getElementById("demo").innerHTML = x + y;
</script>

</body>
</html>

NaN ﺖﺳﺍ ﺩﺪﻋ ﮏﯾ: ﻉﻮﻧ NaN

ﻝﺎﺜﻣ

typeof NaN;

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Numbers</h2>

<p>The typeof NaN is number:</p>

<p id="demo"></p>

<script>
let x = NaN;
document.getElementById("demo").innerHTML = typeof x;
</script>

</body>
</html>



ﺖﯾﺎﻬﻧ ﯽﺑ

ﯽﺑﺖﯾﺎﻬﻧ (ﺎﯾ -Infinity) ﯽﻣﺮﺑ ﺭﺍﺪﻘﻣ ﻦﯾﺮﺘﮔﺭﺰﺑ ﺯﺍ

ﻝﺎﺜﻣ

let myNumber = 2;
// Execute until Infinity
while (myNumber != Infinity) {
    myNumber = myNumber * myNumber;
}

:ﺪﻨﮐ ﯽﻣ ﺩﺎﺠﯾﺍ ﺍﺭ ﺖﯾﺎﻬﻧ ﯽﺑ<"code class="w3-codespan> ﻦﯿﻨﭽﻤﻫ (ﺮﻔﺻ) 0 ﺮﺑ ﻢﯿﺴﻘﺗ

ﻝﺎﺜﻣ

let x =  2 / 0;
let y = -2 / 0;

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Numbers</h2>

<p>Division by zero generates Infinity;</p>

<p id="demo"></p>

<script>
let x = 2/0;
let y = -2/0;
document.getElementById("demo").innerHTML = x + "<br>" + y;
</script>

</body>
</html>


ﯽﺑﺖﯾﺎﻬﻧ ﺖﺳﺍ ﺩﺪﻋ ﮏﯾ: ﯽﺑ ﻉﻮﻧﺖﯾﺎﻬﻧ

ﻝﺎﺜﻣ

typeof Infinity;

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Numbers</h2>

<p>Infinity is a number:</p>

<p id="demo"></p>

<script>
document.getElementById("demo").innerHTML = typeof Infinity;
</script>

</body>
</html>



ﻝﺎﻤﯿﺳﺩﺍﺰﮕﻫ

ﺪﻨﮐ ﯽﻣ ﺮﯿﺴﻔﺗ ﻝﺎﻤﯿﺳﺩﺍﺰﮕﻫ ﺕﺭﻮﺻ ﻪﺑ ﺪﺷﺎﺑ ﺎﻬﻧﺁ ﺯﺍ ﻞﺒﻗ ﻪﮐ ﯽﺗﺭﻮﺻ ﺭﺩ ﺍﺭ ﯼﺩﺪﻋ ﯼﺎﻫ ﺖﺑﺎﺛ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ

ﻝﺎﺜﻣ

let x = 0xFF;

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Numbers</h2>

<p>Numeric constants, preceded by 0x, are interpreted as hexadecimal:</p>

<p id="demo"></p>

<script>
let x = 0xFF;
document.getElementById("demo").innerHTML = "0xFF = " + x;
</script>

</body>
</html>


ﺪﻨﻨﮐ ﯽﻣ ﺮﯿﺴﻔﺗ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫ ﻪﺨﺴﻧ ﺯﺍ ﯽﺧﺮﺑ
.ﺪﯿﺴﯾﻮﻨﻧ (07 ﻞﺜﻣ) ﻝﻭﺍ ﺮﻔﺻ ﺎﺑ ﺍﺭ ﯼﺩﺪﻋ ﺰﮔﺮﻫ

.ﺪﻫﺩ ﯽﻣ ﺶﯾﺎﻤﻧ 10 ﻪﯾﺎﭘ ﯼﺭﺎﺸﻋﺍ ﺕﺭﻮﺻ ﻪﺑ ﺍﺭ ﺩﺍﺪﻋﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ،ﺽﺮﻓ ﺶﯿﭘ ﺭﻮﻃ ﻪﺑ

.ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ 2 ﻪﯾﺎﭘ ﺯﺍ ﺩﺍﺪﻋﺍ ﯽﺟﻭﺮﺧ ﯼﺍﺮﺑ toString() ﺵﻭﺭ ﺯﺍ ﺪﯿﻧﺍﻮﺗ ﯽ

.ﺖﺳﺍ 10 ﻪﯾﺎﭘ ﺭﺎﺸﻋﺍ .ﺖﺳﺍ 16 ﻪﯾﺎﭘ ﻝﺎﻤﯿﺳﺩﺍﺰﮕﻫ

ﻝﺎﺜﻣ

let myNumber = 32;
myNumber.toString(32);
myNumber.toString(16);
myNumber.toString(12);
myNumber.toString(10);
myNumber.toString(8);
myNumber.toString(2);

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Numbers</h2>

<p>The toString() method can output numbers from base 2 to 36:</p>

<p id="demo"></p>

<script>
let myNumber = 32;
document.getElementById("demo").innerHTML =
"Decimal 32 = " + "<br><br>" + 

"Hexatrigesimal (base 36): " + myNumber.toString(36) + "<br>" +
"Duotrigesimal (base 32): " + myNumber.toString(32) + "<br>" +
"Hexadecimal (base 16): " + myNumber.toString(16) + "<br>" +
"Duodecimal (base 12): " + myNumber.toString(12) + "<br>" +
"Decimal (base 10): " + myNumber.toString(10) + "<br>" +
"Octal (base 8): " + myNumber.toString(8) + "<br>" +
"Binary (base 2): " + myNumber.toString(2);
</script>

</body>
</html>

ﺎﯿﺷﺍ ﻥﺍﻮﻨﻋ ﻪﺑ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺩﺍﺪﻋﺍ

:ﺪﻧﻮﺷ ﯽﻣ ﺩﺎﺠﯾﺍ ﻆﻔﻟ ﺯﺍ ﻪﮐ ﺪﻨﺘﺴﻫ ﯽﯾﺍﺪﺘﺑﺍ ﺮﯾﺩﺎﻘﻣ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺩﺍﺪﻋﺍ ﻝﻮﻤﻌﻣ ﺭﻮﻃ ﻪﺑ

let x = 123;

:ﺪﻧﻮﺷ ﻒﯾﺮﻌﺗ new ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ ﺎﺑ ءﺎﯿﺷﺍ ﻥﺍﻮﻨﻋ ﻪﺑ ﺪﻨﻧﺍﻮﺗ ﯽﻣ ﻦﯿﻨﭽﻤﻫ ﺩﺍﺪﻋﺍ ﺎﻣﺍ

let y = new Number(123);

ﻝﺎﺜﻣ

let x = 123;
let y = new Number(123);

.ﺪﯿﻨﮑﻧ ﺩﺎﺠﯾﺍ Number ءﺎﯿﺷﺍ

.ﺪﻫﺩ ﯽﻣ ﺶﻫﺎﮐ ﺍﺭ ﺍﺮﺟﺍ ﺖﻋﺮﺳ ﻭ ﺪﻨﮐ ﯽﻣ ﻩﺪﯿﭽﯿﭘ ﺍﺭ ﺪﮐ new ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ

:ﺪﻨﻨﮐ ﺩﺎﺠﯾﺍ ﯼﺍ ﻩﺮﻈﺘﻨﻣﺮﯿﻏ ﺞﯾﺎﺘﻧ ﺪﻨﻧﺍﻮﺗ ﯽﻣ ءﺎﯿﺷﺍ ﺩﺍﺪﻌﺗ

:ﺪﻨﺘﺴﻫ ﺮﺑﺍﺮﺑ==، x> ﺮﮕﻠﻤﻋ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﻡﺎﮕﻨﻫ

let x = 500;
let y = new Number(500);

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Numbers</h2>

<p>Numbers and Number objects cannot be safely compared:</p>

<p id="demo"></p>

<script>
// x is a number
let x = 500;

// y is an object
let y = new Number(500);
document.getElementById("demo").innerHTML = (x==y);
</script>

</body>
</html>

.ﺪﻨﺘﺴﯿﻧ ﺮﺑﺍﺮﺑ===، x> ﺮﮕﻠﻤﻋ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﻡﺎﮕﻨﻫ

let x = 500;
let y = new Number(500);

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Numbers</h2>

<p>Numbers and Number objects cannot be safely compared:</p>

<p id="demo"></p>

<script>
// x is a number
let x = 500;

// y is an object
let y = new Number(500);

document.getElementById("demo").innerHTML = (x===y);
</script>

</body>
</html>

.ﺪﯿﻨﮐ ﻪﺟﻮﺗ (x===y)(x==y) ﻦﯿﺑ ﺕﻭﺎﻔﺗ ﻪﺑ

(x == y) ؟ﺖﺳﺭﺩﺎﻧ ﺎﯾ ﺖﺳﺍ ﺖﺳﺭﺩ

let x = new Number(500);
let y = new Number(500);

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Numbers</h2>

<p>JavaScript objects cannot be compared:</p>

<p id="demo"></p>

<script>
// x is an object
let x = new Number(500);

// y is an object
let y = new Number(500);

document.getElementById("demo").innerHTML = (x==y);
</script>

</body>
</html>

(x === y) ؟ﺖﺳﺭﺩﺎﻧ ﺎﯾ ﺖﺳﺍ ﺖﺳﺭﺩ

let x = new Number(500);
let y = new Number(500);

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Numbers</h2>

<p>JavaScript objects cannot be compared:</p>

<p id="demo"></p>

<script>
// x is an object
let x = new Number(500);

// y is an object
let y = new Number(500);

document.getElementById("demo").innerHTML = (x===y);
</script>

</body>
</html>

.ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ falseﻪﺸﯿﻤﻫ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﺷ ﻭﺩ ﻪﺴﯾﺎﻘﻣ

ﻞﻣﺎﮐ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻩﺭﺎﻤﺷ ﻊﺟﺮﻣ

:ﺪﯿﻨﮐ ﻪﻌﺟﺍﺮﻣ ﺎﻣ ﻪﺑ ،ﻩﺭﺎﻤﺷ ﻞﻣﺎﮐ ﻊﺟﺮﻣ ﮏﯾ ﯼﺍﺮﺑ

.ﻞﻣﺎﮐ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻩﺭﺎﻤﺷ ﻊﺟﺮﻣ

.ﺖﺳﺍ Number ﯼﺎﻫ ﺵﻭﺭ ﻭ ﺎﻫ ﯽﮔﮋﯾﻭ ﻡﺎﻤﺗ ﺯﺍ ﯽﯾﺎﻫ ﻪﻧﻮﻤﻧ ﻭ ﺕﺎﺤﯿﺿﻮﺗ ﯼﻭﺎﺣ ﻊﺟﺮﻣ

تمامی حقوق محفوظ است. © BasicIT.org • 2023-2024