ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﻨﯾﺰﻫ


فهرست مطالب

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


ECMAScript 2015 (ES6)

.const :ﺩﺮﮐ ﯽﻓﺮﻌﻣ ﺍﺭ ﯼﺪﯾﺪﺟ ﻢﻬﻣ ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭ

:ﺖﺳﺍ ﻩﺪﺷ ﻞﯾﺪﺒﺗ ﻝﻮﻤﻌﻣ ﺵﻭﺭ ﮏﯾ ﻪﺑ const ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺎﺑ ﺎ

ﻝﺎﺜﻣ

const cars = ["Saab", "Volvo", "BMW"];

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

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript const</h2>
<p id="demo"></p>

<script>

const cars = ["Saab", "Volvo", "BMW"];
document.getElementById("demo").innerHTML = cars;

</script>
</body>
</html>

ﺖﺴﯿﻧ ﺩﺪﺠﻣ ﯼﺭﺍﺬﮔﺍﻭ ﻞﺑﺎﻗ

:ﺖﺴﯿﻧ ﺩﺪﺠﻣ ﺺﯿﺼﺨﺗ ﻞﺑﺎﻗ const ﺎﺑ ﻩﺪﺷ ﻡﻼﻋﺍ ﻪﯾﺍﺭﺁ ﮏﯾ

ﻝﺎﺜﻣ

const cars = ["Saab", "Volvo", "BMW"];
cars = ["Toyota", "Volvo", "Audi"];    // ERROR

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

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript const</h2>

<p>You can NOT reassign a constant array:</p>

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

<script>
try {
  const cars = ["Saab", "Volvo", "BMW"];
  cars = ["Toyota", "Volvo", "Audi"];
}
catch (err) {
  document.getElementById("demo").innerHTML = err;
}
</script>

</body>
</html>

ﺪﻨﺘﺴﯿﻧ ﺖﺑﺎﺛ ﺎﻫ ﻪﯾﺍﺭﺁ

.ﺖﺳﺍ ﻩﺪﻨﻨﮐ ﻩﺍﺮﻤﮔ ﯽﻤﮐ const ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ

.ﺪﻨﮐ ﯽﻣ ﻒﯾﺮﻌﺗ ﺍﺭ ﻪﯾﺍﺭﺁ ﮏﯾ ﻪﺑ ﺖﺑﺎﺛ ﻉﺎﺟﺭﺍ ﮏﯾ .ﺪﻨﮐ ﯽﻤﻧ ﻒﯾﺮﻌﺗ ﺖﺑﺎﺛ ﻪﯾﺍﺭﺁ ﮏﯾ

.ﻢﯿﻫﺩ ﺮﯿﯿﻐﺗ ﺍﺭ ﺖﺑﺎﺛ ﻪﯾﺍﺭﺁ ﮏﯾ ﺮﺻﺎﻨﻋ ﻢﯿﻧﺍﻮﺗ ﯽﻣ ﻢﻫ ﺯﻮﻨﻫ ﺎﻣ ،ﻞﯿﻟﺩ ﻦﯿﻤﻫ ﻪﺑ


ﺩﺍﺩ ﺺﯿﺼﺨﺗ ﻩﺭﺎﺑﻭﺩ ﻥﺍﻮﺗ ﯽﻣ ﺍﺭ ﺮﺻﺎﻨﻋ

:ﺪﯿﻫﺩ ﺮﯿﯿﻐﺗ ﺍﺭ ﺖﺑﺎﺛ ﻪﯾﺍﺭﺁ ﮏﯾ ﺮﺻﺎﻨﻋ ﺪﯿﻧﺍﻮﺗ ﯽﻣ

ﻝﺎﺜﻣ

// You can create a constant array:
const cars = ["Saab", "Volvo", "BMW"];

// You can change an element:
cars[0] = "Toyota";

// You can add an element:
cars.push("Audi");

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

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript const</h2>

<p>Declaring a constant array does NOT make the elements unchangeable:</p>

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

<script>
// Create an Array:
const cars = ["Saab", "Volvo", "BMW"];

// Change an element:
cars[0] = "Toyota";

// Add an element:
cars.push("Audi");

// Display the Array:
document.getElementById("demo").innerHTML = cars; 
</script>

</body>
</html>

ﺮﮔﺭﻭﺮﻣ ﯽﻧﺎﺒﯿﺘﺸﭘ

.ﺩﻮﺷ ﯽﻤﻧ ﯽﻧﺎﺒﯿﺘﺸﭘ ﻥﺁ ﺯﺍ ﻞﺒﻗ ﺎﯾ 10 ﺭﺭﻮﻠﭙﺴﮐﺍ ﺖﻧﺮﺘﻨﯾﺍ ﺭﺩ const

:ﺪﻨﮐ ﯽﻣ ﻒﯾﺮﻌﺗ const ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ ﺯﺍ ﻞﻣﺎﮐ ﯽﻧﺎﺒﯿﺘﺸﭘ ﺎﺑ ﺍ

Chrome 49 IE 11 / Edge Firefox 36 Safari 10 Opera 36
Mar, 2016 Oct, 2013 Feb, 2015 Sep, 2016 Mar, 2016

ﺪﺷ ﻩﺩﺍﺩ ﺹﺎﺼﺘﺧﺍ ﺪﺷ ﻡﻼﻋﺍ ﻪﮐ ﯽﻧﺎﻣﺯ

:ﺩﻮﺷ ﻩﺩﺍﺩ ﺹﺎﺼﺘﺧﺍ ﺎﻬﻧﺁ ﻪﺑ ﺭﺍﺪﻘﻣ ﮏﯾ ﺪﻧﻮﺷﯽﻣ ﻥﻼﻋﺍ ﻪﮐ ﯽﻧﺎﻣﺯ ﺪﯾﺎﺑ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ

ﺖﺳﺍ ﻮﺤﻧ ﮏﯾ ﻪﯾﺍﺭﺁ ﻪﯿﻟﻭﺍ ﯽﻫﺩﺭﺍﺪﻘﻣ ﻥﻭﺪﺑ const ﺯﺍ ﻩﺩﺎﻔﺘﺳ

ﻝﺎﺜﻣ

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

const cars;
cars = ["Saab", "Volvo", "BMW"];

.ﺩﺮﮐ ﻪﯿﻟﻭﺍ ﯽﻫﺩﺭﺍﺪﻘﻣ ﻥﺎﻣﺯ ﺮﻫ ﺭﺩ ﻥﺍﻮﺗ ﯽﻣ ﺍﺭ var ﺎﺑ ﻩﺪﺷ

:ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﻡﻼﻋﺍ ﺯﺍ ﻞﺒﻗ ﻪﯾﺍﺭﺁ ﺯﺍ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ﯽﺘﺣ

ﻝﺎﺜﻣ

:ﺖﺳﺍ ﺏﻮﺧ ﻦﯾﺍ

cars = ["Saab", "Volvo", "BMW"];
var cars;

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

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>JavaScript Hoisting</h2>

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

<script>

cars = ["Saab", "Volvo", "BMW"];
var cars;

document.getElementById("demo").innerHTML = cars[0];

</script>
</body>
</html>

Const Block Scope

.ﺖﺳﺍ Block Scope ﯼﺍﺭﺍﺩ const ﺎﺑ ﻩﺪﺷ ﻡﻼﻋﺍ ﻪﯾﺍﺭ

:ﺖﺴﯿﻧ ﻥﺎﺴﮑﯾ ﺖﺳﺍ ﻩﺪﺷ ﻡﻼﻋﺍ ﮎﻮﻠﺑ ﺯﺍ ﺝﺭﺎﺧ ﻪﮐ ﯼﺍ ﻪﯾﺍﺭﺁ ﺎﺑ ﮎﻮﻠﺑ ﮏﯾ ﺭﺩ ﻩﺪﺷ ﻡﻼﻋﺍ ﻪﯾﺍﺭﺁ ﮏﯾ

ﻝﺎﺜﻣ

const cars = ["Saab", "Volvo", "BMW"];
// Here cars[0] is "Saab"
{
  const cars = ["Toyota", "Volvo", "BMW"];
 
  // Here cars[0] is "Toyota"
}
// Here cars[0] is "Saab"

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

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>Declaring an Array Using const</h2>

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

<script>
const cars = ["Saab", "Volvo", "BMW"];
// Here cars[0] is "Saab"
{  
  const cars = ["Toyota", "Volvo", "BMW"]; 
  // Here cars[0] is "Toyota"
}
// Here cars[0] is "Saab"
document.getElementById("demo").innerHTML = cars[0];
</script>

</body>
</html>

:ﺩﺭﺍﺪﻧ ﮎﻮﻠﺑ ﻩﺩﻭﺪﺤﻣ ،ﺖﺳﺍ ﻩﺪﺷ ﻡﻼﻋﺍ var ﺎﺑ ﻪﮐ ﯼﺍ ﻪﯾﺍﺭﺁ

ﻝﺎﺜﻣ

var cars = ["Saab", "Volvo", "BMW"];
// Here cars[0] is "Saab"
{
  var cars = ["Toyota", "Volvo", "BMW"];
 
  // Here cars[0] is "Toyota"
}
// Here cars[0] is "Toyota"

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

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1> 
<h2>Declaring an Array Using var</h2>

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

<script>
var cars = ["Saab", "Volvo", "BMW"];
// Here cars[0] is "Saab"
{  
  var cars = ["Toyota", "Volvo", "BMW"]; 
  // Here cars[0] is "Toyota"
}
// Here cars[0] is "Toyota"
document.getElementById("demo").innerHTML = cars[0];
</script>

</body>
</html>

.ﺪﯿﻨﮐ ﺐﺴﮐ ﯼﺮﺘﺸﯿﺑ ﺕﺎﻋﻼﻃﺍ JavaScript Scope :ﺶﺨﺑ ﺭﺩ Block Scope ﺩﺭﻮﻣ ﺭﺩ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ﺎﻤﺷ



ﺎﻫ ﻪﯾﺍﺭﺁ ﺩﺪﺠﻣ ﻡﻼﻋﺍ

:ﺖﺳﺍ ﺯﺎﺠﻣ ﻪﻣﺎﻧﺮﺑ ﺯﺍ ﯽﯾﺎﺟ ﺮﻫ ﺭﺩ ﺖﺳﺍ ﻩﺪﺷ ﻡﻼﻋﺍ var ﺎﺑ ﻪ

ﻝﺎﺜﻣ

var cars = ["Volvo", "BMW"];   // Allowed
var cars = ["Toyota", "BMW"];  // Allowed
cars = ["Volvo", "Saab"];      // Allowed

ﺭﺩ ﺎﯾ ﻩﺩﻭﺪﺤﻣ ﻥﺎﻤﻫ ﺭﺩ ،const ﻪﺑ ﻪﯾﺍﺭﺁ ﮏﯾ ﺩﺪﺠﻣ ﺺﯿﺼﺨﺗ ﺎ

ﻝﺎﺜﻣ

var cars = ["Volvo", "BMW"];     // Allowed
const cars = ["Volvo", "BMW"];   // Not allowed
{
  var cars = ["Volvo", "BMW"];   // Allowed
  const cars = ["Volvo", "BMW"]; // Not allowed
}

ﺭﺩ ﺎﯾ ﻩﺩﻭﺪﺤﻣ ﻥﺎﻤﻫ ﺭﺩ ،ﺩﻮﺟﻮﻣ const ﻪﯾﺍﺭﺁ ﮏﯾ ﺩﺪﺠﻣ ﺺﯿﺼﺨ

ﻝﺎﺜﻣ

const cars = ["Volvo", "BMW"];   // Allowed
const cars = ["Volvo", "BMW"];   // Not allowed
var cars = ["Volvo", "BMW"];     // Not allowed
cars = ["Volvo", "BMW"];         // Not allowed

{
  const cars = ["Volvo", "BMW"]; // Allowed
  const cars = ["Volvo", "BMW"]; // Not allowed
  var cars = ["Volvo", "BMW"];   // Not allowed
  cars = ["Volvo", "BMW"];       // Not allowed
}

:ﺖﺳﺍ ﺯﺎﺠﻣ ﺮﮕﯾﺩ ﮎﻮﻠﺑ ﺭﺩ ﺎﯾ ﺮﮕﯾﺩ ﻩﺩﻭﺪﺤﻣ ﺭﺩ ،const ﺎﺑ ﯼ

ﻝﺎﺜﻣ

const cars = ["Volvo", "BMW"];   // Allowed
{
  const cars = ["Volvo", "BMW"]; // Allowed
}
{
  const cars = ["Volvo", "BMW"]; // Allowed
}

ﻪﯾﺍﺭﺁ ﻞﻣﺎﮐ ﻊﺟﺮﻣ

:ﺪﯾﻭﺮﺑ ﺎﻣ ﺱﺭﺩﺁ ﻪﺑ ،ﻪﯾﺍﺭﺁ ﻞﻣﺎﮐ ﻊﺟﺮﻣ ﮏﯾ ﯼﺍﺮﺑ

.ﻞﻣﺎﮐ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﯾﺍﺭﺁ ﻊﺟﺮﻣ

ﺖﺳﺍ ﺎﻫ ﻪﯾﺍﺭﺁ ﻪﻤﻫ ﺯﺍ ﯽﯾﺎﻫ ﻪﻧﻮﻤﻧ ﻭ ﺕﺎﺤﯿﺿﻮﺗ ﯼﻭﺎﺣ ﻊﺟﺮﻣ

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