eval() ﺯﺍ ﺏﺎﻨﺘﺟﺍ ،==
.ﺪﯿﻧﺎﺳﺮﺑ ﻞﻗﺍﺪﺣ ﻪﺑ ﺍﺭ ﯼﺮﺳﺍﺮﺳ ﯼﺎﻫﺮﯿﻐﺘﻣ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ
.ﺩﻮﺷ ﯽﻣ ﻊﺑﺍﻮﺗ ﻭ ءﺎﯿﺷﺍ ،ﺎﻫ ﻩﺩﺍﺩ ﻉﺍﻮﻧﺍ ﻡﺎﻤﺗ ﻞﻣﺎﺷ ﻦﯾﺍ
.ﺩﺮﮐ ﯽﺴﯾﻮﻧﺯﺎﺑ ﺮﮕﯾﺩ ﯼﺎﻫ ﺖﭙﯾﺮﮑﺳﺍ ﻂﺳﻮﺗ ﻥﺍﻮﺗ ﯽﻣ ﺍﺭ ﯼﺮﺳﺍﺮﺳ ﻊﺑﺍﻮﺗ ﻭ ﺎﻫﺮﯿﻐﺘﻣ
ﺪﯾﺮﯿﮕﺑ ﺩﺎﯾ ﺍﺭ ﻩﺩﺎﻔﺘﺳﺍ ﻩﻮﺤﻧ ﻭ ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﯽﻠﺤﻣ ﯼﺎﻫﺮﯿﻐﺘﻣ ﺯﺍ ﻥﺁ ﯼﺎﺟ ﻪﺑ
.ﺪﻧﻮﺷ ﻥﻼﻋﺍ ﯽﻠﺤﻣ ﯼﺎﻫﺮﯿﻐﺘﻣ ﻥﺍﻮﻨﻋ ﻪﺑ ﺪﯾﺎﺑ ﻊﺑﺎﺗ ﮏﯾ ﺭﺩ ﻩﺪﺷ ﻩﺩﺎﻔﺘﺳﺍ ﯼﺎﻫﺮﯿﻐ
،ﺪﻧﻮﺷ ﻥﻼﻋﺍ var ﺎﺑ ﺪﯾﺎﺑ ﯽﻠﺤﻣ ﯼﺎﻫﺮﯿﻐﺘ
.ﺪﺷﺎﺑ ﻩﺪﺸﻧ ﻡﻼﻋﺍ ﯼﺎﻫﺮﯿﻐﺘﻣ ﺪﻫﺩ ﯽﻤﻧ ﻩﺯﺎﺟﺍ ﻪﻧﺍﺮﯿﮔ ﺖﺨﺳ ﺖﻟﺎﺣ
ﺖﺳﺍ ﺏﻮﺧ ﯽﺴﯾﻮﻧﺪﮐ ﻦﯾﺮﻤﺗ ﮏﯾ ﺖﭙﯾﺮﮑﺳﺍ ﺮﻫ ﯼﻻﺎﺑ ﺭﺩ ﺎﻫ ﻥﻼﻋﺍ ﻡﺎﻤﺗ ﻥﺩﺍﺩ ﺭﺍﺮﻗ
:ﻩﺩﺍﺭﺍ ﻦﯾﺍ
ﻩﺪﺑ ﻩﺪﻨﻨﮐ ﮎﺎﭘ ﺪﮐ
ﺪﯿﻨﮐ ﻢﻫﺍﺮﻓ ﯽﻠﺤﻣ ﯼﺎﻫﺮﯿﻐﺘﻣ ﯼﻮﺠﺘﺴﺟ ﯼﺍﺮﺑ ﺪﺣﺍﻭ ﻥﺎﮑﻣ ﮏﯾ
ﺪﯿﻨﮐ ﺮﺗ ﻥﺎﺳﺁ ﺍﺭ (ﯽﺤﯾﻮﻠﺗ) ﻪﺘﺳﺍﻮﺧﺎﻧ ﯼﺮﺳﺍﺮﺳ ﯼﺎﻫﺮﯿﻐﺘﻣ ﺯﺍ ﯼﺮﯿﮔﻮﻠﺟ
ﻪﺘﺳﺍﻮﺧﺎﻧ ﺩﺪﺠﻣ ﻡﻼﻋﺍ ﻝﺎﻤﺘﺣﺍ ﺶﻫﺎﮐ
// Declare at the beginning
let firstName, lastName, price, discount, fullPrice;
// Use later
firstName = "John";
lastName = "Doe";
price = 19.90;
discount = 0.10;
fullPrice = price - discount;:ﺪﻨﮐ ﯽﻣ ﻕﺪﺻ ﻪﻘﻠﺣ ﯼﺎﻫﺮﯿﻐﺘﻣ ﯼﺍﺮﺑ ﻦﯿﻨﭽﻤﻫ ﻦﯾﺍ
for (let i = 0; i < 5; i++)
{.ﺪﯿﻨﮐ ﻪﯿﻟﻭﺍ ﯽﻫﺩﺭﺍﺪﻘﻣ ﺪﯿﻨﮐ ﯽﻣ ﻡﻼﻋﺍ ﺍﺭ ﺎﻬﻧﺁ ﻪﮐ ﯽﻧﺎﻣﺯ ﺍﺭ ﺎﻫﺮﯿﻐﺘﻣ ﻪﮐ ﺖﺳﺍ ﺏﻮﺧ ﯽﺴﯾﻮﻧ ﺪﮐ ﻦﯾﺮ
:ﻩﺩﺍﺭﺍ ﻦﯾﺍ
ﻩﺪﺑ ﻩﺪﻨﻨﮐ ﮎﺎﭘ ﺪﮐ
ﺪﯿﻨﮐ ﻢﻫﺍﺮﻓ ﺎﻫﺮﯿﻐﺘﻣ ﻪﯿﻟﻭﺍ ﯽﻫﺩﺭﺍﺪﻘﻣ ﯼﺍﺮﺑ ﺪﺣﺍﻭ ﻥﺎﮑﻣ ﮏﯾ
ﺪﯿﻨﮐ ﺏﺎﻨﺘﺟﺍ ﻩﺪﺸﻧ ﻒﯾﺮﻌﺗ ﺮﯾﺩﺎﻘﻣ ﺯﺍ
// Declare and initiate at the beginning
let firstName = "";
let lastName = "";
let price = 0;
let discount = 0;
let fullPrice = 0,
const myArray = [];
const myObject = {};.ﺪﻫﺩ ﯽﻣ ﻪﺋﺍﺭﺍ ﺍﺭ (ﺮﻈﻧ ﺩﺭﻮﻣ ﻩﺩﺍﺩ ﻉﻮﻧ ﻭ) ﺮﻈﻧ ﺩﺭﻮﻣ ﺩﺮﺑﺭﺎﮐ ﺯﺍ ﯼﺍ ﻩﺪﯾﺍ ﺎﻫﺮﯿﻐﺘﻣ ﻪﯿﻟﻭﺍ ﯽﻫﺩﺭﺍ
:ﺪﻨﮐ ﯽﻣ ﯼﺮﯿﮔﻮﻠﺟ ﻉﻮﻧ ﯽﻓﺩﺎﺼﺗ ﺮﯿﯿﻐﺗ ﻪﻧﻮﮔﺮﻫ ﺯﺍ const ﺎﺑ ﺎﯿﺷﺍ ﻥﻼﻋﺍ
let car = {type:"Fiat", model:"500", color:"white"};
car = "Fiat"; // Changes object to stringconst car = {type:"Fiat", model:"500", color:"white"};
car = "Fiat"; // Not possible:ﺪﻨﮐ ﯽﻣ ﯼﺮﯿﮔﻮﻠﺟ ﻉﻮﻧ ﯽﻓﺩﺎﺼﺗ ﺮﯿﯿﻐﺗ ﻪﻧﻮﮔﺮﻫ ﺯﺍ const ﺎﺑ ﺎﻫ ﻪﯾﺍﺭﺁ ﻥﻼﻋﺍ
let cars = ["Saab", "Volvo", "BMW"];
cars = 3; // Changes array to numberconst cars = ["Saab", "Volvo", "BMW"];
cars = 3; // Not possibleﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ "" ﺯﺍ new Str
ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ 0 ﺯﺍ new Numb
ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ false ﺯﺍ new
ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ {} ﺯﺍ new Obj
ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ [] ﺯﺍ new Arr
ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ /()/ ﺯﺍ new R
ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ new Function() ﯼﺎﺟ ﻪﺑ {}() ﻊﺑﺎﺗ<
let x1 = ""; // new primitive string
let x2 = 0; // new primitive number
let x3 = false; // new primitive boolean
const x4 = {}; // new object
const x5 = []; // new array object
const x6 = /()/; // new regexp object
const x7 = function(){}; // new function object→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Literal Constructors</h2>
<p id="demo"></p>
<script>
let x1 = "";
let x2 = 0;
let x3 = false;
const x4 = {};
const x5 = [];
const x6 = /()/;
const x7 = function(){};
document.getElementById("demo").innerHTML =
"x1: " + typeof x1 + "<br>" +
"x2: " + typeof x2 + "<br>" +
"x3: " + typeof x3 + "<br>" +
"x4: " + typeof x4 + "<br>" +
"x5: " + typeof x5 + "<br>" +
"x6: " + typeof x6 + "<br>" +
"x7: " + typeof x7 + "<br>";
</script>
</body>
</html>
.ﺖﺳﺍ ﻩﺪﺷ ﭗﯾﺎﺗ ﻞﺷ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ
.ﺪﺷﺎﺑ ﺎﻫ ﻩﺩﺍﺩ ﻉﺍﻮﻧﺍ ﻡﺎﻤﺗ ﻞﻣﺎﺷ ﺪﻧﺍﻮﺗ ﯽﻣ ﺮﯿﻐﺘﻣ ﮏﯾ
:ﺪﻫﺩ ﺮﯿﯿﻐﺗ ﺍﺭ ﺩﻮﺧ ﻩﺩﺍﺩ ﻉﻮﻧ ﺪﻧﺍﻮﺗ ﯽﻣ ﺮﯿﻐﺘﻣ ﮏﯾ
let x = "Hello"; // typeof x is a string
x = 5; // changes typeof x to a number→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Variables</h2>
<p>A variable can chang its type. In this example x is first a string then a number:</p>
<p id="demo"></p>
<script>
let x = "Hello";
x = 5;
document.getElementById("demo").innerHTML = typeof x;
</script>
</body>
</html>
ﻪﻧ) ﺪﻧﻮﺷ ﻞﯾﺪﺒﺗ NaN ﺎﯾ ﻪﺘﺷﺭ ﻪﺑ ﯽﻓﺩﺎﺼﺗ ﺭﻮﻃ ﻪﺑ ﺖﺳﺍ ﻦﮑﻤﻣ
:ﺪﻨﮐ ﻞﯾﺪﺒﺗ ﻪﺘﺷﺭ ﻪﺑ ﺍﺭ ﺩﺍﺪﻋﺍ ﺪﻧﺍﻮﺗ ﯽﻣ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ،ﯽﺿﺎﯾﺭ ﺕﺎﯿﻠﻤﻋ ﻡﺎﺠﻧﺍ ﻡﺎﮕﻨﻫ
let x = 5 + 7; // x.valueOf() is 12, typeof x is a number
let x = 5 + "7"; // x.valueOf() is 57, typeof x is a string
let x = "5" + 7; // x.valueOf() is 57, typeof x is a string
let x = 5 - 7; // x.valueOf() is -2, typeof x is a number
let x = 5 - "7"; // x.valueOf() is -2, typeof x is a number
let x = "5" - 7; // x.valueOf() is -2, typeof x is a number
let x = 5 - "x"; // x.valueOf() is NaN, typeof x is a number→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Variables</h2>
<p>Remove the comment (at the beginning of the lines) to test each case:</p>
<p id="demo"></p>
<script>
let x = 5;
//x = 5 + 7; // x.valueOf() is 12, typeof x is a number
//x = 5 + "7"; // x.valueOf() is 57, typeof x is a string
//x = "5" + 7; // x.valueOf() is 57, typeof x is a string
//x = 5 - 7; // x.valueOf() is -2, typeof x is a number
//x = 5 - "7"; // x.valueOf() is -2, typeof x is a number
//x = "5" - 7; // x.valueOf() is -2, typeof x is a number
//x = 5 - "x"; // x.valueOf() is NaN, typeof x is a number
document.getElementById("demo").innerHTML = x.valueOf() + " " + typeof x;
</script>
</body>
</html>
ﺩﻮﺷ ﯽﻤﻧ ﻡﺎﺠﻧﺍ ،ﻪﺘﺷﺭ ﮏﯾ ﺯﺍ ﻪﺘﺷﺭ ﮏﯾ ﻥﺩﺮﮐ ﻢﮐ
"Hello" - "Dolly" // returns NaN→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Variables</h2>
<p>Subtracting a string from a string, does not generate an error but returns NaN (Not a Number):</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = "Hello" - "Dolly";
</script>
</body>
</html>
ﺯﺍ ﻞﺒﻗ (ﻖﺒﻄﻨﻣ ﻉﺍﻮﻧﺍ ﻪﺑ) ﻪﺸﯿﻤﻫ == ﻪﺴﯾﺎﻘﻣ ﺮﮕﻠﻤﻋ
:ﺪﻨﮐ ﯽﻣ ﺭﻮﺒﺠﻣ ﺍﺭ ﻉﻮﻧ ﻭ ﺮﯾﺩﺎﻘﻣ ﻪﺴﯾﺎﻘﻣ === ﺮﮕﻠﻤﻋ
0 == ""; // true
1 == "1"; // true
1 == true; // true
0 === ""; // false
1 === "1"; // false
1 === true;
// false→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Comparisons</h2>
<p>Remove the comment (at the beginning of each line) to test each case:</p>
<p id="demo"></p>
<script>
let x;
//x = (0 == ""); // true
//x = (1 == "1"); // true
//x = (1 == true); // true
//x = (0 === ""); // false
//x = (1 === "1"); // false
//x = (1 === true); // false
document.getElementById("demo").innerHTML = x;
</script>
</body>
</html>
ﺖﺳﺍ ﻪﺘﻓﺭ ﺖﺳﺩ ﺯﺍ ﻥﺁ ﺭﺍﺪﻘﻣ ،ﺩﻮﺷ ﯽﻧﺍﻮﺧﺍﺮﻓ ﻩﺪﺷ ﻢﮔ ﻥﺎﻣﻮﮔﺭﺁ ﺎﺑ ﯽﻌﺑﺎﺗ ﺮﮔﺍ
ﺖﺳﺍ ﺏﻮﺧ ﺕﺩﺎﻋ ﮏﯾ ﺽﺮﻓ ﺶﯿﭘ ﺺﯿﺼﺨﺗ .ﺪﻨﻨﮑﺸﺑ ﺍﺭ ﺎﻤﺷ ﺪﮐ ﺪﻨﻧﺍﻮﺗ ﯽﻣ ﻩﺪﺸﻧ ﻒﯾﺮﻌﺗ ﺮﯾﺩﺎﻘﻣ
function myFunction(x, y) {
if (y === undefined) {
y = 0;
}
}→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Functions</h2>
<p>Setting a default value to a function parameter.</p>
<p id="demo"></p>
<script>
function myFunction(x, y) {
if (y === undefined) {
y = 0;
}
return x * y;
}
document.getElementById("demo").innerHTML = myFunction(4);
</script>
</body>
</html>
ECMAScript 2015 ﺪﻫﺩ ﯽﻣ ﻩﺯﺎﺟﺍ ﻊﺑﺎﺗ ﻒﯾﺮﻌﺗ ﺭﺩ ﺽﺮﻓ ﺶﯿﭘ ﯼﺎﻫﺮﺘﻣﺍﺭﺎﭘ ﻪﺑ:
function (a=1, b=1) { /*function code*/ }ﺪﯿﻧﺍﻮﺨﺑ ﺮﺘﺸﯿﺑ ﻊﺑﺎﺗ ﯼﺎﻫﺮﺘﻣﺍﺭﺎﭘ ﺭﺩ ﺎﻫ ﻥﺎﻣﻮﮔﺭﺁ ﻭ ﻊﺑﺎﺗ ﯼﺎﻫﺮﺘﻣﺍﺭﺎﭘ ﺩﺭﻮﻣ ﺭﺩ
ﺩﺭﺍﺩ ﺩﻮﺟﻭ ﺪﯿﻨﮐ ﯽﻣ ﺮﮑﻓ ﺮﮔﺍ ﯽﺘﺣ .ﺪﯿﻫﺩ ﻥﺎﯾﺎﭘ ﺽﺮﻓﺶﯿﭘ<"code class="w3-codespan
switch (new Date().getDay()) {
case 0:
day = "Sunday";
break;
case 1:
day = "Monday";
break;
case 2:
day = "Tuesday";
break;
case 3:
day = "Wednesday";
break;
case 4:
day = "Thursday";
break;
case 5:
day = "Friday";
break;
case 6:
day = "Saturday";
break;
default:
day =
"Unknown";
}→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
let day;
switch (new Date().getDay()) {
case 0:
day = "Sunday";
break;
case 1:
day = "Monday";
break;
case 2:
day = "Tuesday";
break;
case 3:
day = "Wednesday";
break;
case 4:
day = "Thursday";
break;
case 5:
day = "Friday";
break;
case 6:
day = "Saturday";
break;
default:
day = "unknown";
}
document.getElementById("demo").innerHTML = "Today is " + day;
</script>
</body>
</html>
ﻥﺍﻮﻨﻋ ﻪﺑ ﻪﻧ .ﺪﯾﺮﯿﮕﺑ ﺮﻈﻧ ﺭﺩ ﻪﯿﻟﻭﺍ ﺮﯾﺩﺎﻘﻣ ﻥﺍﻮﻨﻋ ﻪﺑ ﺍﺭ ﺎﻫ ﯽﻟﻮﺑ ﺎﯾ ﺎﻫ ﻪﺘﺷﺭ ،ﺩﺍﺪﻋﺍ ﻪﺸﯿﻤﻫ
،ﺪﻫﺩ ﯽﻣ ﺶﻫﺎﮐ ﺍﺭ ﺍﺮﺟﺍ ﺖﻋﺮﺳ ،ﺎﯿﺷﺍ ﻥﺍﻮﻨﻋ ﻪﺑ ﻉﻮﻧ ﻦﯾﺍ ﻡﻼﻋﺍ
let x = "John";
let y = new String("John");
(x === y) // is false because x is a string and y is an object.→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript String Objects</h2>
<p>Never create strings as objects.</p>
<p>Strings and objects cannot be safely compared.</p>
<p id="demo"></p>
<script>
let x = "John"; // x is a string
let y = new String("John"); // y is an object
document.getElementById("demo").innerHTML = (x === y);
</script>
</body>
</html>
:ﺮﺗﺪﺑ ﯽﺘﺣ ﺎﯾ
let x = new String("John");
let y = new String("John");
(x == y) // is false because you cannot compare objects.→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript String Objects</h2>
<p>Never create strings as objects.</p>
<p>JavaScript cannot compare objects.</p>
<p id="demo"></p>
<script>
let x = new String("John");
let y = new String("John");
document.getElementById("demo").innerHTML = (x == y);
</script>
</body>
</html>
ﺍﺭ ﻥﺁ ،ﺩﺭﺍﻮﻣ ﻪﻤﻫ ﺭﺩ ﺎﺒﯾﺮﻘﺗ .ﺩﻮﺷ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﺪﮐ ﻥﺍﻮﻨﻋ ﻪﺑ ﻦﺘﻣ ﯼﺍﺮﺟﺍ ﯼﺍﺮﺑ
ﺪﻫﺩ ﯽﻣ ﻥﺎﺸﻧ ﺍﺭ ﺖﯿﻨﻣﺍ ﮏﯾ ﻦﯿﻨﭽﻤﻫ ،ﺩﻮﺷ ﺍﺮﺟﺍ ﻩﺍﻮﺨﻟﺩ ﺪﮐ ﺪﻫﺩ ﯽﻣ ﻩﺯﺎﺟﺍ ﻪﮐ ﺎﺠﻧﺁ ﺯﺍ