ﺩﺍﺪﻋﺍ ﻪﺑ ﺎﻫ ﻪﺘﺷﺭ ﻞﯾﺪﺒﺗ
ﻪﺘﺷﺭ ﻪﺑ ﺩﺍﺪﻋﺍ ﻞﯾﺪﺒﺗ
ﺩﺍﺪﻋﺍ ﻪﺑ ﺦﯾﺭﺎﺗ ﻞﯾﺪﺒﺗ
ﺦﯾﺭﺎﺗ ﻪﺑ ﺩﺍﺪﻋﺍ ﻞﯾﺪﺒﺗ
ﺩﺍﺪﻋﺍ ﻪﺑ ﺎﻫ ﯽﻟﻮﺑ ﻞﯾﺪﺒﺗ
ﯽﻟﻮﺑ ﻪﺑ ﺩﺍﺪﻋﺍ ﻞﯾﺪﺒﺗ
:ﺩﺮﮐ ﻞﯾﺪﺒﺗ ﯼﺮﮕﯾﺩ ﻩﺩﺍﺩ ﻉﻮﻧ ﻭ ﺪﯾﺪﺟ ﺮﯿﻐﺘﻣ ﮏﯾ ﻪﺑ ﻥﺍﻮﺗ ﯽﻣ ﺍﺭ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫﺮﯿﻐﺘﻣ
ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻊﺑﺎﺗ ﮏﯾ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺎﺑ
ﺭﺎﮐﺩﻮﺧ ﺕﺭﻮﺻ ﻪﺑ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺩﻮﺧ ﻂﺳﻮﺗ
.ﺪﻨﮐ ﯽﻣ ﻞﯾﺪﺒﺗ ﺩﺪﻋ ﻪﺑ ﺍﺭ (ﺭﺍﺪﻘﻣ ﮏﯾ ﺎﯾ) ﺮﯿﻐﺘﻣ ﮏﯾ .(3.14 ﺪﻨﻧﺎﻣ) ﺩﻮﺷ ﯽﻣ ﻞﯾﺪﺒﺗ ﺩﺪﻋ ﮏﯾ ﻪﺑ ("3.14" ﺪﻨﻧﺎﻣ) ﯼﺩﺪﻋ ﻪﺘﺷﺭ ﮏﯾ .ﺩﻮﺷ ﯽﻣ ﻞﯾﺪﺒﺗ 0 ﻪﺑ ("" ﺪﻨﻧﺎﻣ) ﯽﻟﺎﺧ ﻪﺘﺷﺭ ﮏﯾ .ﺩﻮﺷ ﯽﻣ ﻞﯾﺪﺒﺗ (ﺖﺴﯿﻧ ﺩﺪﻋ) :ﺩﺮﮐ ﺪﻨﻫﺍﻮﺧ ﻞﯾﺪﺒﺗ ﺎﻬﻨﯾﺍ :ﺪﻧﻮﺷ ﯽﻤﻧ ﻞﯾﺪﺒﺗ ﺎﻬﻨﯾﺍ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ ﺎﻤﺷ ،ﻩﺭﺎﻤﺷ ﯼﺎﻫ ﺵﻭﺭ ﻞﺼﻓ ﺭﺩ ﺡﺮﺷ ﺖﺳﺍ ﻩﺪﺷ ﻞﯾﺪﺒﺗ ﻥﺁ ﻥﺎﻣﻮﮔﺭﺁ ﺯﺍ ﻪﮐ ﺪﻧﺍﺩﺮﮔﯽﻣﺮﺑ ﺍﺭ ﯼﺩﺪﻋ ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ ﺭﻭﺎﻨﺷ ﺰﯿﻤﻣ ﺩﺪﻋ ﮏﯾ ﻭ ﺪﻨﮐ ﯽﻣ ﻪﯾﺰﺠﺗ ﺍﺭ ﻪﺘﺷﺭ ﮏﯾ ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺢﯿﺤﺻ ﺩﺪﻋ ﮏﯾ ﻭ ﺪﻨﮐ ﯽﻣ ﻪﯾﺰﺠﺗ ﺍﺭ ﻪﺘﺷﺭ ﮏﯾ ﺩﺮﮐ ﻩﺩﺎﻔﺘﺳﺍ unary + operator ﺯﺍ ﻥﺍﻮﺗ ﯽﻣ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ ﺮﮔﺍ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ .ﺪﻨﮐ ﻞﯾﺪﺒﺗ ﻪﺘﺷﺭ ﻪﺑ ﺍﺭ ﺩﺍﺪﻋﺍ ﺪﻧﺍﻮﺗ ﯽﻣ :ﺩﺮﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺕﺭﺎﺒﻋ ﺎﯾ ﺮﯿﻐﺘﻣ ،ﻆﻔﻟ ،ﺩﺍﺪﻋﺍ ﻉﻮﻧ ﺮﻫ ﯼﻭﺭ ﺮﺑ ﺍﺭ ﻥﺁ ﻥﺍﻮﺗ ﯽﻣ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ .ﺪﻨﮐ ﯽﻣ ﺍﺭ ﺭﺎﮐ ﻦﯿﻤﻫ ﺰﯿﻧ Number()
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>
ﯼﺩﺪﻋ ﯼﺎﻫ ﺵﻭﺭ
Unary + ﺭﻮﺗﺍﺮﭘﺍ
ﻝﺎﺜﻣ
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>
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>
ﺎﻤﺷ ،ﻩﺭﺎﻤﺷ ﯼﺎﻫ ﺵﻭﺭ ﻞﺼﻓ ﺭﺩ
.ﺪﻧﺍﺩﺮﮔﯽﻣﺮﺑ ﯽﯾﺎﻤﻧ ﺩﺎﻤﻧ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺎﺑ ﻭ ﻩﺪﺷ ﺩﺮﮔ ﺩﺪﻋ ﺎﺑ ﺍﺭ ﯼﺍﻪﺘﺷﺭ
.ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﻩﺪﺷ ﻪﺘﺷﻮﻧ ﺭﺎﺸﻋﺍ ﺯﺍ ﯽﺼﺨﺸﻣ ﺩﺍﺪﻌﺗ ﺎﺑ ﻭ ﻩﺪﺷ ﺩﺮﮔ ﺩﺪﻋ ﺎﺑ ﺍﺭ ﯼﺍ ﻪﺘﺷﺭ
ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ ﻩﺪﺷ ﻪﺘﺷﻮﻧ ﺺﺨﺸﻣ ﻝﻮﻃ ﺎﺑ ﺩﺪﻋ ﮏﯾ ﺎﺑ ﻪﺘﺷﺭ ﮏﯾ
ﻪﺑ ﺦﯾﺭﺎﺗ ﻞﯾﺪﺒﺗ ﯼﺍﺮﺑ ﺪﻧﺍﻮﺗ ﯽﻣ 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)"
.ﺪﻨﮐ ﯽﻣ ﺍﺭ ﺭﺎﮐ ﻦﯿﻤﻫ ﺰﯿﻧ ﺎﻤﺷ ،ﺦﯾﺭﺎﺗ ﯼﺎﻫ ﺵﻭﺭ ﻞﺼﻓ ﺭﺩ (31-1) ﺩﺪﻋ ﮏﯾ ﻥﺍﻮﻨﻋ ﻪﺑ ﺯﻭﺭ ﺖﻓﺎﯾﺭﺩ (6-0) ﺪﯿﻨﮐ ﺖﻓﺎﯾﺭﺩ ﺍﺭ ﻪﺘﻔﻫ ﺯﻭﺭ ﻩﺭﺎﻤﺷ (Yyyyy) ﺪﯿﻨﮐ ﺖﻓﺎﯾﺭﺩ ﺍﺭ ﯽﻤﻗﺭ ﺭﺎﻬﭼ ﻝﺎﺳ (23-0) ﺖﻋﺎﺳ ﺖﻓﺎﯾﺭﺩ (999-0) ﻪﯿﻧﺎﺛ ﯽﻠﯿﻣ ﺖﻓﺎﯾﺭﺩ (59-0) ﻪﻘﯿﻗﺩ ﺖﻓﺎﯾﺭﺩ (11-0) ﻩﺎﻣ ﺖﻓﺎﯾﺭﺩ (59-0) ﻪﯿﻧﺎﺛ ﺖﻓﺎﯾﺭﺩ (1970 ﻪﯾﻮﻧﺍﮊ 1 ﺯﺍ ﻪﯿﻧﺎﺛ ﯽﻠﯿﻣ) ﻥﺎﻣﺯ ﺖﻓﺎﯾﺭﺩ .ﺪﻨﮐ ﻞﯾﺪﺒﺗ ﺩﺍﺪﻋﺍ ﻪﺑ ﺍﺭ Booleans ﺪﻧﺍﻮﺗﯽﻣ ﻦﯿﻨﭽﻤﻫ ﻪﺑ ﺍﺭ Booleans ﺪﻧﺍﻮﺗ ﯽﻣ .ﺪﻨﮐ ﯽﻣ ﺍﺭ ﺭﺎﮐ ﻦﯿﻤﻫ ﺰﯿﻧ ﺪﻫﺩ ﻡﺎﺠﻧﺍ ﺍﺭ ﺭﺎﮐ ﻦﯾﺍ ﺪﻨﮐ ﯽﻣ ﯽﻌﺳ ،ﺪﻨﮐ ﺭﺎﮐ "ﻩﺎﺒﺘﺷﺍ" ﻩﺩﺍﺩ ﻉﻮﻧ ﮏﯾ ﯼﻭﺭ ﺪﻨﮐ ﯽﻣ ﯽﻌﺳ ﺖﭙﯾﺮﮑﺳﺍ :ﺪﯾﺭﺍﺩ ﺭﺎﻈﺘﻧﺍ ﺎﻤﺷ ﻪﮐ ﺖﺴﯿﻧ ﯼﺰﯿﭼ ﻥﺁ ﻪﺸﯿﻤﻫ ﻪﺠﯿﺘﻧ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ .ﺪﻨﮐ ﯽﻣ ﯽﻧﺍﻮﺧﺍﺮﻓ ﻥﺎﺤﺘﻣﺍ ﻡﺎﮕﻨﻫ ﺍﺭ ﺮﯿﻐﺘﻣ :ﺖﺴﯿﻧ ﻩﺪﻫﺎﺸﻣ ﻞﺑﺎﻗ ﯽﻠﯿﺧ ﻦﯾﺍ ﺎﻣﺍ ،ﺪﻧﻮﺷ ﯽﻣ ﻞﯾﺪﺒﺗ ﺰﯿﻧ ﺎﻫ ﯽﻟﻮﺑ ﻭ ﺩﺍﺪﻋﺍ :ﺪﻫﺩ ﯽﻣ ﻥﺎﺸﻧ ﺍﺭ Boolean ﻭ Number، String ﻪﺑ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻒﻠﺘﺨﻣ ﺮﯾﺩﺎﻘﻣ ﻞﯾﺪﺒﺗ ﻪﺠﯿﺘﻧ ﻝﻭﺪ ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ: ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ: ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ: ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ: → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ: ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ: ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ: ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ: → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ: ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ: ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ: ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ: → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ: ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ: ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ: ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ: → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ: ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ: ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ: ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ: → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ: ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ: ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ: ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ: → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ: ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ: ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ: ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ: → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ: ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ: ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ: ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ: → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ: ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ: ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ: ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ: → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ: ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ: ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ: ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ: → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ: ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ: ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ: ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ: → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ: ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ: ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ: ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ: → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ: ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ: ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ: ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ: → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ: ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ: ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ: ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ: → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ: ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ: ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ: ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ: → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ: ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ: ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ: ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ: → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ: ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ: ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ: ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ: → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ: ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ: ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ: ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ: → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ: ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ: ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ: ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ: → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ: ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ: ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ: ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ: → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ: ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ: ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ: ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ: → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﯽﻠﺻﺍ ﺭﺍﺪﻘﻣ: ﻩﺭﺎﻤﺷ ﻪﺑ ﻞﯾﺪﺒﺗ: ﻪﺘﺷﺭ ﻪﺑ ﻞﯾﺪﺒﺗ: ﯽﻟﻮﺑ ﻪﺑ ﻞﯾﺪﺒﺗ: → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ .ﺪﻫﺩ ﯽﻣ ﻥﺎﺸﻧ ﺍﺭ ﻪﺘﺷﺭ ﺮﯾﺩﺎﻘﻣ ﻝﻮﻗ ﻞﻘﻧ ﺭﺩ ﺮﯾﺩﺎﻘﻣ ﺰﻣﺮﻗ ﺮﯾﺩﺎﻘﻣ ﺪﻨﺷﺎﺑ ﻪﺘﺷﺍﺪﻧ ﺭﺎﻈﺘﻧﺍ ﺖﺳﺍ ﻦﮑﻤﻣ ﻥﺎﺴﯾﻮﻧ ﻪﻣﺎﻧﺮﺑ ﻝﺎﺜﻣ
Date().toString() // returns "Thu Jul 17 2014 15:38:19 GMT+0200 (W. Europe Daylight Time)"
ﺩﺍﺪﻋﺍ ﻪﺑ ﺎﻫ ﯽﻟﻮﺑ ﻞﯾﺪﺒﺗ
Number(
Number(false) // returns 0
Number(true) // returns 1
ﻪﺘﺷﺭ ﻪﺑ 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"
ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻉﻮﻧ ﻞﯾﺪﺒﺗ ﻝﻭﺪﺟ
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>