.ﺪﻨﮐ ﯽﻣ ﻩﺭﺎﺷﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺞﯾﺍﺭ ﺕﺎﻫﺎﺒﺘﺷﺍ ﺯﺍ ﯽﺧﺮﺑ ﻪﺑ ﻞﺼﻓ ﻦﯾﺍ
ﺪﻨﻨﮐ ﺩﺎﺠﯾﺍ ﺲﯾﻮﻧﻪﻣﺎﻧﺮﺑ ﺩﻮﺟﻭ ﺕﺭﻮﺻ ﺭﺩ ﺍﺭ ﯼﺍﻩﺮﻈﺘﻨﻣﺮﯿﻏ ﺞﯾﺎﺘﻧ ﺖﺳﺍ ﻦﮑﻤﻣ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭ
ﻥﺍﻮﻨﻋ ﻪﺑ) ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ ﻪﻧ ﺪﯾﺎﺷ) ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧﺖﺳﺭﺩﺎﻧ<"code class="w3-codespan">if
let x = 0;
if (x == 10)
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Comparisons</h2>
<p>This returns false (as expected) because x is not equal to 10:</p>
<p id="demo"></p>
<script>
let x = 0;
document.getElementById("demo").innerHTML = Boolean(x == 10);
</script>
</body>
</html>
ﺖﺳﺭﺩ<"code class="w3-codespan">if
let x = 0;
if (x = 10)
<!DOCTYPE html>
<html>
<body>
<h2>Common JavaScript Mistakes</h2>
<p>This returns true (maybe not as expected), because 10 is true:</p>
<p id="demo"></p>
<script>
let x = 0;
document.getElementById("demo").innerHTML = Boolean(x = 10);
</script>
</body>
</html>
ﻪﻧ ﺪﯾﺎﺷ) ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ .ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ ﺏﺎﺴﺘﻧﺍ ﺭﺍﺪﻘﻣ ﻪﺸﯿﻤﻫ ﺏﺎﺴﺘﻧﺍ ﮏﯾ ﺩﺩﺮﮔ ﯽﻣﺮﺑ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ :ﺪﻧﺍﺩﺮﮔﯽﻣﺮﺑ ﺍﺭ code class="w3-codespan">ifﺖﺳﺭﺩﺎﻧ<"code class="w3-codespan">if
false> ﺕﺭﺎﺒﻋ ﻦﯾﺍ .ﺖﺳﺍ ﻢﻬﻣ ﻩﺩﺍﺩlet x = 0;
if (x = 0)
<!DOCTYPE html>
<html>
<body>
<h2>Common JavaScript Mistakes</h2>
<p>This if statement returns false (maybe not as expected), because 0 is false:</p>
<p id="demo"></p>
<script>
let x = 0;
document.getElementById("demo").innerHTML = Boolean(x = 0);
</script>
</body>
</html>
ﺖﺴﺳ ﻪﺴﯾﺎﻘﻣ ﺭﺎﻈﺘﻧﺍ
if
ﺕﺭﺎﺒﻋ ﻦﯾﺍ .ﺖﺴﯿﻧ ﻢﻬﻣ ﻩﺩﺍﺩ ﻉﻮﻧ ،ﯽﻟﻮﻤﻌﻣ ﻪﺴlet x = 10;
let y = "10";
if (x == y)
<!DOCTYPE html>
<html>
<body>
<h2>Common JavaScript Mistakes</h2>
<p>In regular comparison, data type does not matter. This if statement returns true:</p>
<p id="demo"></p>
<script>
let x = 10;
let y = "10";
document.getElementById("demo").innerHTML = Boolean(x == y);
</script>
</body>
</html>
let x = 10;
let y = "10";
if (x === y)
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>Common JavaScript Mistakes</h2>
<p>In strict comparison, data type does matter. This if statement returns false:</p>
<p id="demo"></p>
<script>
let x = 10;
let y = "10";
document.getElementById("demo").innerHTML = Boolean(x === y);
</script>
</body>
</html>
.ﺩﻮﺷ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﻪﻧﺍﺮﯿﮕﺘﺨﺳ switch
ﺕﺍﺭﻮﺘﺳﺩ ﺭﺩ ﻢﯿﻨﮐ ﺵﻮﻣ
:ﺪﻫﺩ ﯽﻣ ﺶﯾﺎﻤﻧ ﺭﺍﺪﺸﻫ ﮏﯾ ﺩﺭﻮﻣ ﭻﯿﺋﻮﺳ<"code class="w3-codespan> ﻦﯾﺍ
let x = 10;
switch(x) {
case 10: alert("Hello");
}
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>Common JavaScript Mistakes</h2>
<p>It is a common mistake to forget that switch statements use strict comparison.</p>
<p>This will work:</p>
<p id="demo"></p>
<script>
let x = 10;
switch(x) {
case 10: document.getElementById("demo").innerHTML = "Hello";
}
</script>
</body>
</html>
:ﺪﻫﺩ ﯽﻤﻧ ﺶﯾﺎﻤﻧ ﺍﺭ ﯼﺭﺍﺪﺸﻫ ﺩﺭﻮﻣ ﭻﯿﺋﻮﺳ<"code class="w3-codespan> ﻦﯾﺍ
let x = 10;
switch(x) {
case "10": alert("Hello");
}
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>Common JavaScript Mistakes</h2>
<p>It is a common mistake to forget that switch statements use strict comparison.</p>
<p>This will not work:</p>
<p id="demo"></p>
<script>
let x = 10;
switch(x) {
case "10": document.getElementById("demo").innerHTML = "Hello";
}
</script>
</body>
</html>
ﻥﺩﻭﺰﻓﺍ ﻥﺩﻭﺰﻓﺍ ﺩﺭﻮﻣ ﺭﺩ ﺩﺍﺪﻋﺍ ﺖﺳﺍ.
Concatenation ﻥﺩﻭﺰﻓﺍ ﺩﺭﻮﻣ ﺭﺩ ﻪﺘﺷﺭ ﺖﺳﺍ.
.ﺪﻨﻨﮐ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ +
ﺮﮕﻠﻤﻋ ﮏﯾ ﺯﺍ ﺕﺎﯿﻠﻤﻋ ﻭﺩ ﺮﻫ ﺖﭙﯾﺮﮑﺳﺍ
ﺩﻮﺑ ﺪﻫﺍﻮﺧ ﺕﻭﺎﻔﺘﻣ ﺩﺪﻋ ﮏﯾ ﻥﺍﻮﻨﻋ ﻪﺑ ﺩﺪﻋ ﮏﯾ ﻥﺩﺮﮐ ﻪﻓﺎﺿﺍ ،ﻞﯿﻟﺩ ﻦﯿﻤﻫ ﻪﺑ
let x = 10;
x = 10 + 5; //
Now x is 15
let y = 10;
y += "5";
// Now y is "105"
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>Common JavaScript Mistakes</h2>
<p>Adding a number as a number produces a different result from adding a number as a string:</p>
<p id="demo"></p>
<script>
let y = 10
y += "5";
document.getElementById("demo").innerHTML = y;
</script>
</body>
</html>
:ﺪﺷﺎﺑ ﺭﺍﻮﺷﺩ ﺖﺳﺍ ﻦﮑﻤﻣ ﻪﺠﯿﺘﻧ ﯽﻨﯿﺑ ﺶﯿﭘ ،ﺮﯿﻐﺘﻣ ﻭﺩ ﻥﺩﺮﮐ ﻪﻓﺎﺿﺍ ﻡﺎﮕﻨﻫ
let x = 10;
let y = 5;
let z = x + y; // Now z is 15
let x = 10;
let y = "5";
let z = x + y; // Now z is "105"
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>Common JavaScript Mistakes</h2>
<p>Adding a number as a number produces a different result from adding a number as a string:</p>
<p id="demo"></p>
<script>
let x = 10;
let y = "5";
let z = x + y;
document.getElementById("demo").innerHTML = z;
</script>
</body>
</html>
ﺪﻧﻮﺷ ﯽﻣ ﻩﺮﯿﺧﺫ ﯽﺘﯿﺑ 64/>ﺭﻭﺎﻨﺷ ﺰﯿﻤﻣ ﺩﺍﺪﻋﺍ ﻥﺍﻮﻨﻋ ﻪﺑ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺭﺩ ﺩﺍﺪﻋ
ﺪﻧﺭﺍﺩ ﻞﮑﺸﻣ ﻥﺁ ﺎﺑ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﻠﻤﺟ ﺯﺍ ﯽﺴﯾﻮﻧ ﻪﻣﺎﻧﺮﺑ ﯼﺎﻫ ﻥﺎﺑﺯ ﻪﻤﻫ
let x = 0.1;
let y = 0.2;
let z = x + y
// the result in z will not be 0.3
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>Common JavaScript Mistakes</h2>
<p>All programming languages, including JavaScript, have difficulties with precise floating point values:</p>
<p id="demo"></p>
<script>
let x = 0.1;
let y = 0.2;
let z = x + y;
document.getElementById("demo").innerHTML = z;
</script>
</body>
</html>
:ﺪﻨﮐ ﯽﻣ ﮏﻤﮐ ﻢﯿﺴﻘﺗ ﻭ ﺏﺮﺿ ﻪﺑ ،ﻻﺎﺑ ﻞﮑﺸﻣ ﻞﺣ ﯼﺍﺮﺑ
let z = (x * 10 + y * 10) / 10; // z will be 0.3
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>Common JavaScript Mistakes</h2>
<p>All programming languages, including JavaScript, have difficulties with precise floating point values.</p>
<p>To solve the problem, it helps to multiply and divide:</p>
<p id="demo"></p>
<script>
let x = 0.1;
let y = 0.2;
let z = (x * 10 + y *10) / 10;
document.getElementById("demo").innerHTML = z;
</script>
</body>
</html>
:ﺪﯿﻨﮐ ﻢﯿﺴﻘﺗ ﻂﺧ ﻭﺩ ﻪﺑ ﺍﺭ ﺕﺭﺎﺒﻋ ﮏﯾ ﻪﮐ ﺪﻫﺩ ﯽﻣ ﺍﺭ ﻥﺎﮑﻣﺍ ﻦﯾﺍ ﺎﻤﺷ ﻪﺑ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ
let x =
"Hello World!";
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>Breaking a JavaScript Statement</h2>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
"Hello World!";
</script>
</body>
</html>
:ﺩﺮﮐ ﺪﻫﺍﻮﺨﻧ ﺭﺎﮐ ﻪﺘﺷﺭ ﮏﯾ ﻂﺳﻭ ﺭﺩ ﺕﺭﺎﺒﻋ ﮏﯾ ﻦﺘﺴﮑﺷ ﺎﻣﺍ
let x = "Hello
World!";
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>Common JavaScript Mistakes</h2>
<p>Breaking a statement in the middle of a string will not work:</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = "Hello
World!";
</script>
</body>
</html>
:ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ "ﺶﻠﺳﺍ ﮏﺑ" ﺯﺍ ﺪﯾﺎﺑ ،ﺪﯿﻨﮑﺸﺑ ﻪﺘﺷﺭ ﮏﯾ ﺭﺩ ﺍﺭ ﺕﺭﺎﺒﻋ ﮏﯾ ﺪﯾﺎﺑ ﺮﮔﺍ
let x = "Hello \
World!";
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>Common JavaScript Mistakes</h2>
<p>You must use a "backslash" if you must break a statement in a string:</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = "Hello \
World!";
</script>
</body>
</html>
ﺪﺷ ﺪﻫﺍﻮﺧ ﺍﺮﺟﺍ ﻪﺑ ﻪﺟﻮﺗ ﻥﻭﺪﺑ ﺪﮐ ﮎﻮﻠﺑ ﻦﯾﺍ ،ﺎﺠﺑﺎﻧ ﻝﻮﮔﺮﯾﻭ ﻪﻄﻘﻧ ﮏﯾ ﻞﯿﻟﺩ ﻪﺑ
if (x == 19);
{
// code block
}
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>Common JavaScript Mistakes</h2>
<p id="demo"></p>
<script>
let x = 5;
if (x == 19);
{
document.getElementById("demo").innerHTML = "Hello";
}
</script>
</body>
</html>
ﺪﻨﮐﯽﻣ ﻪﺘﺴﺑ ﺖﻤﺴﻗ ﺭﺩ ﺭﺎﮐﺩﻮﺧ ﺭﻮﻃﻪﺑ ﺍﺭ ﺭﻮﺘﺳﺩ ﮏﯾ ﻪﮐ ﺖﺳﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺽﺮﻓﺶﯿﭘ
:ﺩﺍﺩ ﺪﻨﻫﺍﻮﺧ ﻥﺎﺸﻧ ﺍﺭ ﯽﻧﺎﺴﮑﯾ ﻪﺠﯿﺘﻧ ﻝﺎﺜﻣ ﻭﺩ ﻦﯾﺍ ،ﻞﯿﻟﺩ ﻦﯿﻤﻫ ﻪﺑ
function myFunction(a) {
let power = 10
return a * power
}
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>Common JavaScript Mistakes</h2>
<p>This example will return a correct result:</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = myFunction(55);
function myFunction(a) {
let power = 10
return a * power
}
</script>
</body>
</html>
function myFunction(a) {
let power = 10;
return a * power;
}
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>Common JavaScript Mistakes</h2>
<p>This example will return a correct result:</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = myFunction(55);
function myFunction(a) {
let power = 10;
return a * power;
}
</script>
</body>
</html>
.ﺪﯿﻨﮐ ﻢﯿﺴﻘﺗ ﻂﺧ ﻭﺩ ﻪﺑ ﺍﺭ ﺕﺭﺎﺒﻋ ﮏﯾ ﻪﮐ ﺪﻫﺩ ﯽﻣ ﺍﺭ ﻥﺎﮑﻣﺍ ﻦﯾﺍ ﺎﻤﺷ ﻪﺑ ﻦﯿﻨﭽﻤﻫ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ
:ﺪﻫﺩ ﯽﻣ ﻥﺎﺸﻧ ﺍﺭ ﻪﺠﯿﺘﻧ ﻥﺎﻤﻫ ﺰﯿﻧ 3 ﻝﺎﺜﻣ ،ﻞﯿﻟﺩ ﻦﯿﻤﻫ ﻪﺑ
function myFunction(a) {
let
power = 10;
return a * power;
}
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>Common JavaScript Mistakes</h2>
<p>This example will return a correct result:</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = myFunction(55);
function myFunction(a) {
let
power = 10;
return a * power;
}
</script>
</body>
</html>
ﺪﯿﻨﮑﺸﺑ ﺪﻨﻧﺎﻣ ﻂﺧ ﻭﺩ ﺭﺩ ﺍﺭ return ﺕﺭﺎﺒﻋ ﺮﮔﺍ ﺪﺘﻓﺍﯽﻣ ﯽﻗﺎﻔﺗﺍ ﻪﭼ ،ﺎﻣﺍ
function myFunction(a) {
let
power = 10;
return
a * power;
}
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>Common JavaScript Mistakes</h2>
<p>This example will return undefined:</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = myFunction(55);
function myFunction(a) {
let
power = 10;
return
a * power;
}
</script>
</body>
</html>
!ﺪﻧﺍﺩﺮﮔﯽﻣﺮﺑ ﺍﺭ ﻩﺪﺸﻧ ﻒﯾﺮﻌﺗ<"code class="w3-codespan> ﻊﺑﺎﺗ
:ﺖﺳﺍ ﻦﯾﺍ ﺎﻤﺷ ﺭﻮﻈﻨﻣ ﺩﺮﮐ ﯽﻣ ﺮﮑﻓ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺍﺮﯾﺯ ؟ﺍﺮﭼ
function myFunction(a) {
let
power = 10;
return;
a * power;
}
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>Common JavaScript Mistakes</h2>
<p>This example will return undefined:</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = myFunction(55);
function myFunction(a) {
let
power = 10;
return;
a * power;
}
</script>
</body>
</html>
:ﺪﻨﻧﺎﻣ ﺪﺷﺎﺑ ﺺﻗﺎﻧ ﺕﺭﺎﺒﻋ ﮏﯾ ﺮﮔﺍ
let
:ﺪﻨﮐ ﻞﻣﺎﮐ ﺍﺭ ﺕﺭﺎﺒﻋ ﯼﺪﻌﺑ ﻂﺧ ﻥﺪﻧﺍﻮﺧ ﺎﺑ ﺪﻨﮐ ﯽﻣ ﯽﻌﺳ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ
power = 10;
:ﺖﺳﺍ ﻞﻣﺎﮐ ﻪﯿﻧﺎﯿﺑ ﻦﯾﺍ ﻪﮐ ﯽﯾﺎﺠﻧﺁ ﺯﺍ ﺎﻣﺍ
return
:ﺩﺪﻨﺑ ﯽﻣ ﺮﯾﺯ ﺕﺭﻮﺻ ﻪﺑ ﺍﺭ ﻥﺁ ﺭﺎﮐﺩﻮﺧ ﺕﺭﻮﺻ ﻪﺑ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ
return;
ﺖﺳﺍ ﯼﺭﺎﯿﺘﺧﺍ ﻝﻮﮔﺮﯾﻭ ﻪﻄﻘﻧ ﺎﺑ (ﻥﺩﺍﺩ ﻥﺎﯾﺎﭘ) ﺕﺍﺭﺎﺒﻋ ﻦﺘﺴﺑ ﺍﺮﯾﺯ ﺪﺘﻓﺍﯽﻣ ﻕﺎﻔﺗﺍ ﻦﯾﺍ
ﺍﺮﯾﺯ ،ﺩﺪﻨﺑ ﯽﻣ ﻂﺧ ﯼﺎﻬﺘﻧﺍ ﺭﺩ ﺍﺭ return ﺕﺭﺎﺒﻋ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ
.ﺪﯿﻨﮑﺸﻧ ﺍﺭ ﺖﺸﮔﺯﺎﺑ ﻪﯿﻧﺎﯿﺑ ﺰﮔﺮﻫ
.ﺪﻨﻨﮐ ﯽﻣ ﯽﻧﺎﺒﯿﺘﺸﭘ ﻩﺪﺷ ﯼﺭﺍﺬﮕﻣﺎﻧ ﯼﺎﻫ ﻪﯾﺎﻤﻧ ﺎﺑ ﯽﯾﺎﻫ ﻪﯾﺍﺭﺁ ﺯﺍ ﯽﺴﯾﻮﻧ ﻪﻣﺎﻧﺮﺑ ﯼﺎﻫ ﻥﺎﺑﺯ ﺯﺍ ﯼﺭ
ﺪﻧﻮﺷ ﯽﻣ ﻩﺪﯿﻣﺎﻧ ﯽﻨﻤﺠﻧﺍ ﺪﻧﺭﺍﺩ ﻩﺪﺷ ﯼﺭﺍﺬﮕﻣﺎﻧ ﯼﺎﻫ ﺺﺧﺎﺷ ﻪﮐ ﯽﯾﺎﻫ ﻪﯾﺍﺭﺁ
.ﺪﻨﮐ ﯽﻤﻧ ﯽﻧﺎﺒﯿﺘﺸﭘ ﻥ ﻩﺪﺷ ﯼﺭﺍﺬﮕﻣﺎﻧ ﯼﺎﻫ ﻪﯾﺎﻤﻧ ﯼﺍﺭﺍﺩ ﯼﺎﻫ ﻪﯾﺍﺭﺁ ﺯﺍ ﺖﭙﯾﺮﮑﺳ
:ﺪﻨﻨﮐ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﻩﺪﺷ ﯼﺭﺍﺬﮔ ﻩﺭﺎﻤﺷ ﯼﺎﻫ ﺺﺧﺎﺷ ﺯﺍ ﺎﻫ ﻪﯾﺍﺭﺁ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ .ﺪﻨﻨﮐﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﻩﺪﺷ ﯼﺭﺍﺬﮔﻡﺎﻧ ﯼﺎﻫﺺﺧﺎﺷ ﺯﺍ ءﺎﯿﺷ ﺪﻨﮐ ﯽﻣ ﻒﯾﺮﻌﺗ ﻩﺭﺎﺑﻭﺩ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ،ﻪﯾﺍﺭﺁ ﮏﯾ ﻪﺑ ﯽﺳﺮﺘﺳﺩ ﻡﺎﮕﻨﻫ ،ﺪﯿﻨﮐ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﻡﺎﻧ ﺎﺑ ﻪﯾ ﺪﻨﻨﮐﯽﻣ ﺪﯿﻟﻮﺗ ﻩﺪﺸﻧ ﻒﯾﺮﻌﺗ ﺎﯾ ﻪﯾﺍﺭﺁ ﯼﺎﻫﯽﮔﮋﯾﻭ ﻭ ﺎﻫﺵﻭﺭ ،ﺭﺎﮐﺩﻮﺧ ﺩﺪﺠﻣ ﻒﯾﺮﻌﺗ ﺯ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ .ﺪﻨﺘﺴﻫ ﯽﻧﻮﻧﺎﻗ ECMAScript 5 ﺭﺩ ﻪﯾﺍﺭﺁ ﻭ ﯽﺷ ﻒﯾﺮﻌﺗ ﺭﺩ ﯽﯾﺎﻬﺘﻧﺍ ﯼﺎﻫﺎﻣﺎﮐ !!ﺭﺍﺪﺸﻫ .ﺩﻮﺷ ﯽﻣ ﺏﺍﺮﺧ 8 ﺭﺭﻮﻠﭙﺴﮐﺍ ﺖﻧﺮﺘﻨﯾﺍ JSON ﺪﻫﺩ ﯽﻤﻧ ﺍﺭ ﯽﯾﺎﻬﺘﻧﺍ ﯼﺎﻫﺎﻣﺎﮐ ﻩﺯﺎﺟﺍ. .ﺪﻨﺷﺎﺑ .ﺪﻨﺷﺎﺑ ﻪﺘﺷﺍﺩ .ﺪﻨﮐ ﺭﺍﻮﺷﺩ ﯽﻤﮐ ﺍﺭ ﯽﺷ ﮏﯾ ﻥﺩﻮﺑ ﯽﻟﺎﺧ ﺶﯾﺎﻣﺯﺁ ﺪﻧﺍﻮﺗ ﯽﻣ ﻦﯾﺍ :ﺪﯿﻨﮐ ﺶﯾﺎﻣﺯﺁ ﺍﺭ ﯽﺷ ﮏﯾ ﺩﻮﺟﻭ ،ﺖﺳﺍ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ ﺮﮔﺍ ﺍﺮﯾﺯ ،ﺖﺳﺍ ،ﺖﺴﯿﻧ :ﺪﻨﮐ ﺩﺎﺠﯾﺍ ﺎﻄﺧ ﮏﯾ ﺪﻧﺍﻮﺗ ﯽﻣ ﻢﻫ ﺯﻮﻨﻫ ﻦﯾﺍ ﺎﻣﺍ ﺪﯿﻨﮐ ﺶﯾﺎﻣﺯﺁ ﺍﺭ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ ﻝﺎﺜﻣ
const person = [];
person[0] = "John";
person[1] = "Doe";
person[2] = 46;
person.length;
// person.length will return 3
person[0];
// person[0] will return "John"
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<p id="demo"></p>
<script>
const person = [];
person[0] = "John";
person[1] = "Doe";
person[2] = 46;
document.getElementById("demo").innerHTML =
person[0] + " " + person.length;
</script>
</body>
</html>
: ﻝﺎﺜﻣ
const person = [];
person["firstName"] = "John";
person["lastName"] = "Doe";
person["age"] = 46;
person.length; // person.length will
return 0
person[0];
// person[0] will return undefined
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<p>If you use a named index when accessing an array, JavaScript will redefine the array to a standard object, and some array methods and properties will produce undefined or incorrect results.</p>
<p id="demo"></p>
<script>
const person = [];
person["firstName"] = "John";
person["lastName"] = "Doe";
person["age"] = 46;
document.getElementById("demo").innerHTML =
person[0] + " " + person.length;
</script>
</body>
</html>
ﺎﻣﺎﮐ ﺎﺑ ﻒﯾﺭﺎﻌﺗ ﻪﺑ ﻥﺩﺍﺩ ﻥﺎﯾﺎﭘ
:ﯽﺷ ﻝﺎﺜﻣ
person = {firstName:"John", lastName:"Doe", age:46,}
:ﻪﯾﺍﺭﺁ ﻝﺎﺜﻣ
points = [40, 100, 1, 5, 25, 10,];
JSON:
person = {"firstName":"John", "lastName":"Doe", "age":46}
JSON:
points = [40, 100, 1, 5, 25, 10];
Undefined Null ﺖﺴﯿﻧ
ﻩﺪﺸﻧ ﻒﯾﺮﻌﺗ<"code class="w3-codespan> ﺪﻨﻧﺍﻮﺗﯽﻣ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫﺪﺘﻣ
null
ﺭﺍﺪﻘﻣ ﺪﻨﻧﺍﻮﺗ ﯽﻣ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﻟﺎﺧﻩﺪﺸﻧ ﻒﯾﺮﻌﺗ <"code class="w3-codespan> ﻥﺁ ﻉﻮﻧ ﺎ
: ﻝﺎﺜﻣ
if (typeof myObj === "undefined")
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Objects</h2>
<p>To test if an object does not exist, test if the type is undefined:</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = typeof myObj === "undefined";
</script>
</body>
</html>
null
ﯽﺷ ﮏﯾ ﺎﯾﺁ ﻪﮐ ﺪﯿﻨﮐ ﺶﯾﺎﻣﺯﺁ ﺪﯿﻧﺍﻮﺗu2 :ﻂﻠﻏ
if (myObj === null)
null
ﯽﺷ ﮏﯾ ﺎﯾﺁ ﻪﮐ ﺪﯿﻨﮐ ﺶﯾﺎﻣﺯﺁ ﺪﯾﺎﺑ ،ﻞﮑﺸﻣ ﻦﯾﺍ ﻞ :ﻂﻠﻏ
if (myObj !== null && typeof myObj
!== "undefined")
undefined
ﺪﯿﻧﺍﻮﺘﺑ ﻪﮑﻨﯾﺍ ﺯﺍ ﻞﺒﻗ ﺪﯾﺎﺑ ، : ﺖﺳﺭﺩ
if (typeof myObj !== "undefined" && myObj !== null)
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Objects</h2>
<p>If you want to test if an object is not null, you must test if it not undefined first.</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = typeof myObj !== "undefined" && myObj !== null;
</script>
</body>
</html>