ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻉﻮﻧ ﻞﯾﺪﺒﺗ


فهرست مطالب

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

  • ﺩﺍﺪﻋﺍ ﻪﺑ ﺎﻫ ﻪﺘﺷﺭ ﻞﯾﺪﺒﺗ

  • ﻪﺘﺷﺭ ﻪﺑ ﺩﺍﺪﻋﺍ ﻞﯾﺪﺒﺗ

  • ﺩﺍﺪﻋﺍ ﻪﺑ ﺦﯾﺭﺎﺗ ﻞﯾﺪﺒﺗ

  • ﺦﯾﺭﺎﺗ ﻪﺑ ﺩﺍﺪﻋﺍ ﻞﯾﺪﺒﺗ

  • ﺩﺍﺪﻋﺍ ﻪﺑ ﺎﻫ ﯽﻟﻮﺑ ﻞﯾﺪﺒﺗ

  • ﯽﻟﻮﺑ ﻪﺑ ﺩﺍﺪﻋﺍ ﻞﯾﺪﺒﺗ

ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻉﻮﻧ ﻞﯾﺪﺒﺗ

:ﺩﺮﮐ ﻞﯾﺪﺒﺗ ﯼﺮﮕﯾﺩ ﻩﺩﺍﺩ ﻉﻮﻧ ﻭ ﺪﯾﺪﺟ ﺮﯿﻐﺘﻣ ﮏﯾ ﻪﺑ ﻥﺍﻮﺗ ﯽﻣ ﺍﺭ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫﺮﯿﻐﺘﻣ

  • ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻊﺑﺎﺗ ﮏﯾ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺎﺑ

  • ﺭﺎﮐﺩﻮﺧ ﺕﺭﻮﺻ ﻪﺑ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺩﻮﺧ ﻂﺳﻮﺗ


ﺩﺍﺪﻋﺍ ﻪﺑ ﺎﻫ ﻪﺘﺷﺭ ﻞﯾﺪﺒﺗ

.ﺪﻨﮐ ﯽﻣ ﻞﯾﺪﺒﺗ ﺩﺪﻋ ﻪﺑ ﺍﺭ (ﺭﺍﺪﻘﻣ ﮏﯾ ﺎﯾ) ﺮﯿﻐﺘﻣ ﮏﯾ Number()

.(3.14 ﺪﻨﻧﺎﻣ) ﺩﻮﺷ ﯽﻣ ﻞﯾﺪﺒﺗ ﺩﺪﻋ ﮏﯾ ﻪﺑ ("3.14" ﺪﻨﻧﺎﻣ) ﯼﺩﺪﻋ ﻪﺘﺷﺭ ﮏﯾ

.ﺩﻮﺷ ﯽﻣ ﻞﯾﺪﺒﺗ 0 ﻪﺑ ("" ﺪﻨﻧﺎﻣ) ﯽﻟﺎﺧ ﻪﺘﺷﺭ ﮏﯾ

.ﺩﻮﺷ ﯽﻣ ﻞﯾﺪﺒﺗ (ﺖﺴﯿﻧ ﺩﺪﻋ) NaN ﻪﺑ ("ﻥﺎﺟ" ﺪﻨﻧﺎﻣ) ﯼﺩﺪﻋ ﺮ

ﺎﻫ ﻝﺎﺜﻣ

:ﺩﺮﮐ ﺪﻨﻫﺍﻮﺧ ﻞﯾﺪﺒﺗ ﺎﻬﻨﯾﺍ

Number("3.14")
Number(Math.PI)
Number(" ")
Number("")

:ﺪﻧﻮﺷ ﯽﻤﻧ ﻞﯾﺪﺒﺗ ﺎﻬﻨﯾﺍ

Number("99 88")
Number("John")

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

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Numbers</h1>
<h2>The Number() Method</h2>

<p>The Number() metod converts a variable (or value) into a number:</p>

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

<script>
document.getElementById("demo").innerHTML =
Number("3.14") + "<br>" +
Number(Math.PI) + "<br>" +
Number("    ") + "<br>" +
Number("") + "<br>" +
Number("99 88") + "<br>" +
Number("John") + "<br>";
</script>

</body>
</html>

ﯼﺩﺪﻋ ﯼﺎﻫ ﺵﻭﺭ

ﺎﻤﺷ ،ﻩﺭﺎﻤﺷ ﯼﺎﻫ ﺵﻭﺭ ﻞﺼﻓ ﺭﺩ

Method

ﺡﺮﺷ

Number()

ﺖﺳﺍ ﻩﺪﺷ ﻞﯾﺪﺒﺗ ﻥﺁ ﻥﺎﻣﻮﮔﺭﺁ ﺯﺍ ﻪﮐ ﺪﻧﺍﺩﺮﮔﯽﻣﺮﺑ ﺍﺭ ﯼﺩﺪﻋ

parseFloat()

ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ ﺭﻭﺎﻨﺷ ﺰﯿﻤﻣ ﺩﺪﻋ ﮏﯾ ﻭ ﺪﻨﮐ ﯽﻣ ﻪﯾﺰﺠﺗ ﺍﺭ ﻪﺘﺷﺭ ﮏﯾ

parseInt()

ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺢﯿﺤﺻ ﺩﺪﻋ ﮏﯾ ﻭ ﺪﻨﮐ ﯽﻣ ﻪﯾﺰﺠﺗ ﺍﺭ ﻪﺘﺷﺭ ﮏﯾ


Unary + ﺭﻮﺗﺍﺮﭘﺍ

ﺩﺮﮐ ﻩﺩﺎﻔﺘﺳﺍ unary + operator ﺯﺍ ﻥﺍﻮﺗ ﯽﻣ

ﻝﺎﺜﻣ

let y = "5";     
// y is a string
let x = + y;      
// x is a number

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

<!DOCTYPE html>
<html>
<body>

<h2>The JavaScript typeof Operator</h2>

<p>The typeof operator returns the type of a variable or expression:</p>

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

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

</body>
</html>


ﺮﮔﺍ

ﻝﺎﺜﻣ

let y = "John";  
// y is a string
let x = + y;      // x is a number (NaN)

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

<!DOCTYPE html>
<html>
<body>

<h2>The JavaScript typeof Operator</h2>

<p>The typeof operator returns the type of a variable or expression:</p>

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

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

</body>
</html>




ﻪﺘﺷﺭ ﻪﺑ ﺩﺍﺪﻋﺍ ﻞﯾﺪﺒﺗ

.ﺪﻨﮐ ﻞﯾﺪﺒﺗ ﻪﺘﺷﺭ ﻪﺑ ﺍﺭ ﺩﺍﺪﻋﺍ ﺪﻧﺍﻮﺗ ﯽﻣ String() ﯽﻧﺎﻬﺟ

:ﺩﺮﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺕﺭﺎﺒﻋ ﺎﯾ ﺮﯿﻐﺘﻣ ،ﻆﻔﻟ ،ﺩﺍﺪﻋﺍ ﻉﻮﻧ ﺮﻫ ﯼﻭﺭ ﺮﺑ ﺍﺭ ﻥﺁ ﻥﺍﻮﺗ ﯽﻣ

ﻝﺎﺜﻣ

String(x)         // returns a string from a number variable x
 String(123)       // returns a string from a number literal 123
 String(100 + 23)  // returns a string from a number from an expression

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

<!DOCTYPE html>
<html>
<body>

<h2>The JavaScript String() Method</h2>

<p>The String() method can convert a number to a string.</p>

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

<script>
let x = 123;
document.getElementById("demo").innerHTML =
  String(x) + "<br>" +
  String(123) + "<br>" +
  String(100 + 23);
</script>
</body>
</html>

.ﺪﻨﮐ ﯽﻣ ﺍﺭ ﺭﺎﮐ ﻦﯿﻤﻫ ﺰﯿﻧ toString()

ﻝﺎﺜﻣ

x.toString()
(123).toString()
(100 + 23).toString()

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

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Number Methods</h2>

<p>The toString() method converts a number to a string.</p>

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

<script>
let x = 123;
document.getElementById("demo").innerHTML =
  x.toString() + "<br>" +
   (123).toString() + "<br>" +
   (100 + 23).toString();
</script>

</body>
</html>

ﺮﺘﺸﯿﺑ ﯼﺎﻫ ﺵﻭﺭ

ﺎﻤﺷ ،ﻩﺭﺎﻤﺷ ﯼﺎﻫ ﺵﻭﺭ ﻞﺼﻓ ﺭﺩ

toExponential()

.ﺪﻧﺍﺩﺮﮔﯽﻣﺮﺑ ﯽﯾﺎﻤﻧ ﺩﺎﻤﻧ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺎﺑ ﻭ ﻩﺪﺷ ﺩﺮﮔ ﺩﺪﻋ ﺎﺑ ﺍﺭ ﯼﺍﻪﺘﺷﺭ

toFixed()

.ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﻩﺪﺷ ﻪﺘﺷﻮﻧ ﺭﺎﺸﻋﺍ ﺯﺍ ﯽﺼﺨﺸﻣ ﺩﺍﺪﻌﺗ ﺎﺑ ﻭ ﻩﺪﺷ ﺩﺮﮔ ﺩﺪﻋ ﺎﺑ ﺍﺭ ﯼﺍ ﻪﺘﺷﺭ

toPrecision()

ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ ﻩﺪﺷ ﻪﺘﺷﻮﻧ ﺺﺨﺸﻣ ﻝﻮﻃ ﺎﺑ ﺩﺪﻋ ﮏﯾ ﺎﺑ ﻪﺘﺷﺭ ﮏﯾ


ﺩﺍﺪﻋﺍ ﻪﺑ ﺦﯾﺭﺎﺗ ﻞﯾﺪﺒﺗ

ﻪﺑ ﺦﯾﺭﺎﺗ ﻞﯾﺪﺒﺗ ﯼﺍﺮﺑ ﺪﻧﺍﻮﺗ ﯽﻣ Number() ﯽﻧﺎﻬﺟ ﺵﻭﺭ

d = new Date();
Number(d)          // returns 1404568027739

.ﺪﻨﮐ ﯽﻣ ﺍﺭ ﺭﺎﮐ ﻦﯿﻤﻫ ﺰﯿﻧ getTime() ﺦﯾﺭﺎﺗ ﺵﻭﺭ

d = new Date();
d.getTime()        // returns 1404568027739

ﻪﺘﺷﺭ ﻪﺑ ﺦﯾﺭﺎﺗ ﻞﯾﺪﺒﺗ

ﻪﺑ ﺍﺭ ﺎﻫ ﺦﯾﺭﺎﺗ ﺪﻧﺍﻮﺗ ﯽﻣ String() ﯽﻧﺎﻬﺟ ﺵﻭﺭ

 String(Date())  // returns "Thu Jul 17 2014 15:38:19 GMT+0200 (W. Europe Daylight Time)"

.ﺪﻨﮐ ﯽﻣ ﺍﺭ ﺭﺎﮐ ﻦﯿﻤﻫ ﺰﯿﻧ toString()

ﻝﺎﺜﻣ

 Date().toString()  // returns "Thu Jul 17 2014 15:38:19 GMT+0200 (W. Europe Daylight Time)"

ﺎﻤﺷ ،ﺦﯾﺭﺎﺗ ﯼﺎﻫ ﺵﻭﺭ ﻞﺼﻓ ﺭﺩ

getDate()

(31-1) ﺩﺪﻋ ﮏﯾ ﻥﺍﻮﻨﻋ ﻪﺑ ﺯﻭﺭ ﺖﻓﺎﯾﺭﺩ

getDay()

(6-0) ﺪﯿﻨﮐ ﺖﻓﺎﯾﺭﺩ ﺍﺭ ﻪﺘﻔﻫ ﺯﻭﺭ ﻩﺭﺎﻤﺷ

getFullYear()

(Yyyyy) ﺪﯿﻨﮐ ﺖﻓﺎﯾﺭﺩ ﺍﺭ ﯽﻤﻗﺭ ﺭﺎﻬﭼ ﻝﺎﺳ

getHours()

(23-0) ﺖﻋﺎﺳ ﺖﻓﺎﯾﺭﺩ

getMilliseconds()

(999-0) ﻪﯿﻧﺎﺛ ﯽﻠﯿﻣ ﺖﻓﺎﯾﺭﺩ

getMinutes()

(59-0) ﻪﻘﯿﻗﺩ ﺖﻓﺎﯾﺭﺩ

getMonth()

(11-0) ﻩﺎﻣ ﺖﻓﺎﯾﺭﺩ

getSeconds()

(59-0) ﻪﯿﻧﺎﺛ ﺖﻓﺎﯾﺭﺩ

getTime()

(1970 ﻪﯾﻮﻧﺍﮊ 1 ﺯﺍ ﻪﯿﻧﺎﺛ ﯽﻠﯿﻣ) ﻥﺎﻣﺯ ﺖﻓﺎﯾﺭﺩ


ﺩﺍﺪﻋﺍ ﻪﺑ ﺎﻫ ﯽﻟﻮﺑ ﻞﯾﺪﺒﺗ

.ﺪﻨﮐ ﻞﯾﺪﺒﺗ ﺩﺍﺪﻋﺍ ﻪﺑ ﺍﺭ Booleans ﺪﻧﺍﻮﺗﯽﻣ ﻦﯿﻨﭽﻤﻫ Number(

Number(false)     // returns 0
Number(true)      // returns 1

ﻪﺘﺷﺭ ﻪﺑ Booleans ﻞﯾﺪﺒﺗ

ﻪﺑ ﺍﺭ Booleans ﺪﻧﺍﻮﺗ ﯽﻣ String() ﯽﻧﺎﻬﺟ ﺪﺘﻣ

String(false)      // returns "false"
String(true)       // returns "true"

.ﺪﻨﮐ ﯽﻣ ﺍﺭ ﺭﺎﮐ ﻦﯿﻤﻫ ﺰﯿﻧ toString() ﯽﻟﻮﺑ ﺵﻭﺭ

false.toString()   // returns "false"
  true.toString()    // returns "true"

ﻉﻮﻧ ﺭﺎﮐﺩﻮﺧ ﻞﯾﺪﺒﺗ

ﺪﻫﺩ ﻡﺎﺠﻧﺍ ﺍﺭ ﺭﺎﮐ ﻦﯾﺍ ﺪﻨﮐ ﯽﻣ ﯽﻌﺳ ،ﺪﻨﮐ ﺭﺎﮐ "ﻩﺎﺒﺘﺷﺍ" ﻩﺩﺍﺩ ﻉﻮﻧ ﮏﯾ ﯼﻭﺭ ﺪﻨﮐ ﯽﻣ ﯽﻌﺳ ﺖﭙﯾﺮﮑﺳﺍ

:ﺪﯾﺭﺍﺩ ﺭﺎﻈﺘﻧﺍ ﺎﻤﺷ ﻪﮐ ﺖﺴﯿﻧ ﯼﺰﯿﭼ ﻥﺁ ﻪﺸﯿﻤﻫ ﻪﺠﯿﺘﻧ

5 + null    // returns 5         because null is converted to 0
"5" + null  // returns "5null"   because null is converted to "null"
"5" + 2     // returns 
    "52"      because 2 is converted to "2"
 "5" - 2     // returns 3         because "5" is converted to 5
"5" * "2"   // returns 
    10        because "5" and "2" are 
    converted to 5 and 2

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

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Type Conversions</h2>

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

<script>
document.getElementById("demo").innerHTML =
(5 + null) + "<br>"  +
("5" + null) + "<br>" +
("5" + 2) + "<br>" +
("5" - 2) + "<br>" +
("5" * "2") + "<br>" +
("5" / "2") + "<br>"
</script>

</body>
</html>



ﻪﺘﺷﺭ ﺭﺎﮐﺩﻮﺧ ﻞﯾﺪﺒﺗ

.ﺪﻨﮐ ﯽﻣ ﯽﻧﺍﻮﺧﺍﺮﻓ ﻥﺎﺤﺘﻣﺍ ﻡﺎﮕﻨﻫ ﺍﺭ ﺮﯿﻐﺘﻣ toString() ﻊﺑ

document.getElementById("demo").innerHTML = myVar;

// if myVar = {name:"Fjohn"}  // toString converts to "[object Object]"
// if myVar = [1,2,3,4]       // toString converts to "1,2,3,4"
// if myVar = new Date()      // toString converts to "Fri Jul 18 2014 09:08:55 GMT+0200"

:ﺖﺴﯿﻧ ﻩﺪﻫﺎﺸﻣ ﻞﺑﺎﻗ ﯽﻠﯿﺧ ﻦﯾﺍ ﺎﻣﺍ ،ﺪﻧﻮﺷ ﯽﻣ ﻞﯾﺪﺒﺗ ﺰﯿﻧ ﺎﻫ ﯽﻟﻮﺑ ﻭ ﺩﺍﺪﻋﺍ

// if myVar = 123             // toString converts to "123"
// if myVar = true            // toString converts to "true"
// if myVar = false           // toString converts to "false"

ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻉﻮﻧ ﻞﯾﺪﺒﺗ ﻝﻭﺪﺟ

:ﺪﻫﺩ ﯽﻣ ﻥﺎﺸﻧ ﺍﺭ Boolean ﻭ Number، String ﻪﺑ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻒﻠﺘﺨﻣ ﺮﯾﺩﺎﻘﻣ ﻞﯾﺪﺒﺗ ﻪﺠﯿﺘﻧ ﻝﻭﺪ


ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ:

false

ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ:

0

ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ:

"false"

ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ:

false

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Type Conversions</h2>

<p>Converting false to other types:</p>

<p id="demo" style="font-family:courier"></p>

<script>
let x = false;
document.getElementById("demo").innerHTML =
"Number : " + Number(x) + "<br>" +
"String : " + String(x) + "<br>" +
"Boolean: " + Boolean(x);
</script>

</body>
</html>



ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ:

true

ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ:

1

ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ:

"true"

ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ:

true

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Type Conversions</h2>

<p>Converting true to other types:</p>

<p id="demo" style="font-family:courier"></p>

<script>
let x = true;
document.getElementById("demo").innerHTML =
"Number : " + Number(x) + "<br>" +
"String : " + String(x) + "<br>" +
"Boolean: " + Boolean(x);
</script>

</body>
</html>



ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ:

0

ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ:

0

ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ:

"0"

ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ:

false

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Type Conversions</h2>

<p>Converting the number 0 to other types:</p>

<p id="demo" style="font-family:courier"></p>

<script>
let x = 0;
document.getElementById("demo").innerHTML =
"Number : " + Number(x) + "<br>" +
"String : " + String(x) + "<br>" +
"Boolean: " + Boolean(x);
</script>

</body>
</html>



ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ:

1

ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ:

1

ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ:

"1"

ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ:

true

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Type Conversions</h2>

<p>Converting the number 1 to other types:</p>

<p id="demo" style="font-family:courier"></p>

<script>
let x = 1;
document.getElementById("demo").innerHTML =
"Number : " + Number(x) + "<br>" +
"String : " + String(x) + "<br>" +
"Boolean: " + Boolean(x);
</script>

</body>
</html>



ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ:

"0"

ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ:

0

ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ:

"0"

ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ:

true

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Type Conversions</h2>

<p>Converting the string "0" to other types:</p>

<p id="demo" style="font-family:courier"></p>

<script>
let x = "0";
document.getElementById("demo").innerHTML =
"Number : " + Number(x) + "<br>" +
"String : " + String(x) + "<br>" +
"Boolean: " + Boolean(x);
</script>

</body>
</html>



ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ:

"000"

ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ:

0

ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ:

"000"

ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ:

true

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Type Conversions</h2>

<p>Converting the string "000" to other types:</p>

<p id="demo" style="font-family:courier"></p>

<script>
let x = "000";
document.getElementById("demo").innerHTML =
"Number : " + Number(x) + "<br>" +
"String : " + String(x) + "<br>" +
"Boolean: " + Boolean(x);
</script>

</body>
</html>



ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ:

"1"

ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ:

1

ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ:

"1"

ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ:

true

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Type Conversions</h2>

<p>Converting the string "1" to other types:</p>

<p id="demo" style="font-family:courier"></p>

<script>
let x = 1;
document.getElementById("demo").innerHTML =
"Number : " + Number(x) + "<br>" +
"String : " + String(x) + "<br>" +
"Boolean: " + Boolean(x);
</script>

</body>
</html>



ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ:

NaN

ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ:

NaN

ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ:

"NaN"

ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ:

false

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Type Conversions</h2>

<p>Converting NaN to other types:</p>

<p id="demo" style="font-family:courier"></p>

<script>
let x = NaN;
document.getElementById("demo").innerHTML =
"Number : " + Number(x) + "<br>" +
"String : " + String(x) + "<br>" +
"Boolean: " + Boolean(x);
</script>

</body>
</html>



ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ:

Infinity

ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ:

Infinity

ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ:

"Infinity"

ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ:

true

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Type Conversions</h2>

<p>Converting Infinity to other types:</p>

<p id="demo" style="font-family:courier"></p>

<script>
let x = Infinity;
document.getElementById("demo").innerHTML =
"Number : " + Number(x) + "<br>" +
"String : " + String(x) + "<br>" +
"Boolean: " + Boolean(x);
</script>

</body>
</html>



ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ:

-Infinity

ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ:

-Infinity

ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ:

"-Infinity"

ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ:

true

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Type Conversions</h2>

<p>Converting -Infinity to other types:</p>

<p id="demo" style="font-family:courier"></p>

<script>
let x = -Infinity;
document.getElementById("demo").innerHTML =
"Number : " + Number(x) + "<br>" +
"String : " + String(x) + "<br>" +
"Boolean: " + Boolean(x);
</script>

</body>
</html>



ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ:

""

ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ:

0

ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ:

""

ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ:

false

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Type Conversions</h2>

<p>Converting an empty string to other types:</p>

<p id="demo" style="font-family:courier"></p>

<script>
let x = "";
document.getElementById("demo").innerHTML =
"Number : " + Number(x) + "<br>" +
"String : " + String(x) + "<br>" +
"Boolean: " + Boolean(x);
</script>

</body>
</html>



ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ:

"20"

ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ:

20

ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ:

"20"

ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ:

true

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Type Conversions</h2>

<p>Converting a numeric string to other types:</p>

<p id="demo" style="font-family:courier"></p>

<script>
let x = "20";
document.getElementById("demo").innerHTML =
"Number : " + Number(x) + "<br>" +
"String : " + String(x) + "<br>" +
"Boolean: " + Boolean(x);
</script>

</body>
</html>



ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ:

NaN

ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ:

"twenty"

ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ:

"twenty"

ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ:

true

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Type Conversions</h2>

<p>Converting a text string to other types:</p>

<p id="demo" style="font-family:courier"></p>

<script>
let x = "twenty";
document.getElementById("demo").innerHTML =
"Number : " + Number(x) + "<br>" +
"String : " + String(x) + "<br>" +
"Boolean: " + Boolean(x);
</script>

</body>
</html>



ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ:

[ ]

ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ:

0

ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ:

""

ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ:

true

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ

<!DOCTYPE html>
<html>
<body>

<p>Converting an empty array to other types:</p>

<p id="demo" style="font-family:courier"></p>

<script>
var x = [];
document.getElementById("demo").innerHTML =
"Number : " + Number(x) + "<br>" +
"String : " + String(x) + "<br>" +
"Boolean: " + Boolean(x);
</script>

</body>
</html>



ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ:

[20]

ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ:

20

ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ:

"20"

ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ:

true

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ

<!DOCTYPE html>
<html>
<body>

<p>Converting an array with one numeric element to other types:</p>

<p id="demo" style="font-family:courier"></p>

<script>
var x = [20];
document.getElementById("demo").innerHTML =
"Number : " + Number(x) + "<br>" +
"String : " + String(x) + "<br>" +
"Boolean: " + Boolean(x);
</script>

</body>
</html>



ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ:

[10,20]

ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ:

NaN

ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ:

"10,20"

ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ:

true

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ

<!DOCTYPE html>
<html>
<body>

<p>Converting an array with two numeric elements to other types:</p>

<p id="demo" style="font-family:courier"></p>

<script>
var x = [10,20];
document.getElementById("demo").innerHTML =
"Number : " + Number(x) + "<br>" +
"String : " + String(x) + "<br>" +
"Boolean: " + Boolean(x);
</script>

</body>
</html>



ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ:

["twenty"]

ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ:

NaN

ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ:

"twenty"

ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ:

true

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ

<!DOCTYPE html>
<html>
<body>

<p>Converting an array with one string element to other types:</p>

<p id="demo" style="font-family:courier"></p>

<script>
var x = ["twenty"];
document.getElementById("demo").innerHTML =
"Number : " + Number(x) + "<br>" +
"String : " + String(x) + "<br>" +
"Boolean: " + Boolean(x);
</script>

</body>
</html>



ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ:

["ten","twenty"]

ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ:

NaN

ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ:

"ten,twenty"

ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ:

true

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ

<!DOCTYPE html>
<html>
<body>

<p>Converting an array with two string element to other types:</p>

<p id="demo" style="font-family:courier"></p>

<script>
var x = ["ten","twenty"];
document.getElementById("demo").innerHTML =
"Number : " + Number(x) + "<br>" +
"String : " + String(x) + "<br>" +
"Boolean: " + Boolean(x);
</script>

</body>
</html>



ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ:

function(){}

ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ:

NaN

ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ:

"function(){}"

ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ:

true

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Type Conversions</h2>

<p>Converting a function to other types:</p>

<p id="demo" style="font-family:courier"></p>

<script>
const x = function(){};
document.getElementById("demo").innerHTML =
"Number : " + Number(x) + "<br>" +
"String : " + String(x) + "<br>" +
"Boolean: " + Boolean(x);
</script>

</body>
</html>



ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ:

{ }

ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ:

NaN

ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ:

"[object Object]"

ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ:

true

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Type Conversions</h2>

<p>Converting an object to other types:</p>

<p id="demo" style="font-family:courier"></p>

<script>
const x = {};
document.getElementById("demo").innerHTML =
"Number : " + Number(x) + "<br>" +
"String : " + String(x) + "<br>" +
"Boolean: " + Boolean(x);
</script>

</body>
</html>



ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ:

null

ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ:

0

ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ:

"null"

ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ:

false

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Type Conversions</h2>

<p>Converting null to other types:</p>

<p id="demo" style="font-family:courier"></p>

<script>
let x = null;
document.getElementById("demo").innerHTML =
"Number : " + Number(x) + "<br>" +
"String : " + String(x) + "<br>" +
"Boolean: " + Boolean(x);
</script>

</body>
</html>



ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ:

undefined

ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ:

NaN

ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ:

"undefined"

ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ:

false

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Type Conversions</h2>

<p>Converting undefined to other types:</p>

<p id="demo" style="font-family:courier"></p>

<script>
let x = undefined;
document.getElementById("demo").innerHTML =
"Number : " + Number(x) + "<br>" +
"String : " + String(x) + "<br>" +
"Boolean: " + Boolean(x);
</script>

</body>
</html>


.ﺪﻫﺩ ﯽﻣ ﻥﺎﺸﻧ ﺍﺭ ﻪﺘﺷﺭ ﺮﯾﺩﺎﻘﻣ ﻝﻮﻗ ﻞﻘﻧ ﺭﺩ ﺮﯾﺩﺎﻘﻣ

ﺰﻣﺮﻗ ﺮﯾﺩﺎﻘﻣ ﺪﻨﺷﺎﺑ ﻪﺘﺷﺍﺪﻧ ﺭﺎﻈﺘﻧﺍ ﺖﺳﺍ ﻦﮑﻤﻣ ﻥﺎﺴﯾﻮﻧ ﻪﻣﺎﻧﺮﺑ