Hoisting ﺶﯿﭘ ﺭﺎﺘﻓﺭﻥﻼﻋﺍ ﻝﺎﻘﺘﻧﺍ ﯼﺍﺮﺑ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺽﺮﻓﺖﺳﺍ ﻥﺁ ﻪﺑ ﺎﻫ
.ﺩﺮﮐ ﻡﻼﻋﺍ ﻥﺁ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺯﺍ ﺲﭘ ﻥﺍﻮﺗ ﯽﻣ ﺍﺭ ﺮﯿﻐﺘﻣ ﮏﯾ ،ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺭﺩ
.ﺩﺮﮐ ﻩﺩﺎﻔﺘﺳﺍ ﻡﻼﻋﺍ ﺯﺍ ﻞﺒﻗ ﻥﺍﻮﺗ ﯽﻣ ﺍﺭ ﺮﯿﻐﺘﻣ ﮏﯾ ؛ﺮﮕﯾﺩ ﺕﺭﺎﺒﻋ ﻪﺑ
1 ﻝﺎﺜﻣ ﻪﺑ ﺍﺭ ﻪﺠﯿﺘﻧ ﻥﺎﻤﻫ 2 ﻝﺎﺜﻣ ﺪﻫﺩ ﯽﻣ:
x = 5; // Assign 5 to x
elem = document.getElementById("demo"); // Find an element
elem.innerHTML = x;
// Display x in the element
var x; // Declare x
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
x = 5; // Assign 5 to x
elem = document.getElementById("demo"); // Find an element
elem.innerHTML = x; // Display x in the element
var x; // Declare x
</script>
</body>
</html>
var x; // Declare x
x = 5; // Assign 5 to x
elem = document.getElementById("demo"); // Find an element
elem.innerHTML = x;
// Display x in the element
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var x; // Declare x
x = 5; // Assign 5 to x
elem = document.getElementById("demo"); // Find an element
elem.innerHTML = x; // Display x in the element
</script>
</body>
</html>
.ﺪﯿﻨﮐ ﮎﺭﺩ ﺍﺭ "ﻥﺩﺮﺑ ﻻﺎﺑ" ﺡﻼﻄﺻﺍ ﺪﯾﺎﺑ ،ﻉﻮﺿﻮﻣ ﻦﯾﺍ ﮎﺭﺩ ﯼﺍﺮﺑ
Hoisting ﺶﯿﭘ ﺭﺎﺘﻓﺭﻥﻼﻋﺍ ﻪﻤﻫ ﻝﺎﻘﺘﻧﺍ ﯼﺍﺮﺑ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺽﺮﻓﺖﺳﺍ ﻥﺁ ﻪﺑ ﺎﻫ
.ﺪﻧﺮﯿﮔﯽﻣ ﺭﺍﺮﻗ ﻻﺎﺑ ﺭﺩ ﺪﻧﺍﻩﺪﺷ ﻒﯾﺮﻌﺗ const
ﻭ
ﺩﺭﺍﺩ ﺭﺍﺮﻗ "ﯽﻧﺎﻣﺯ ﻩﺩﺮﻣ ﻪﻘﻄﻨﻣ" ﺭﺩ ﺍﺪﺘﺑﺍ ﺯﺍ ﺮﯿﻐﺘﻣ
carName = "Volvo";
let carName;
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Hoisting</h2>
<p>With <b>let</b>, you cannot use a variable before it is declared.</p>
<p id="demo"></p>
<script>
try {
carName = "Saab";
let carName = "Volvo";
}
catch(err) {
document.getElementById("demo").innerHTML = err;
}
</script>
</body>
</html>
.ﺖﺳﺍ ﯼﻮﺤﻧ ﯼﺎﻄﺧ ﮏﯾ ،ﻡﻼﻋﺍ ﺯﺍ ﻞﺒﻗ const
ﺮﯿﻐﺘﻣ ﺯﺍ ﻩﺩﺎﻔﺘﺳ
.ﺩﻮﺷ ﯽﻤﻧ ﺍﺮﺟﺍ ﺪﮐ ﻦﯾﺍ
carName = "Volvo";
const carName;
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Hoisting</h2>
<p>With <b>const</b>, you cannot use a variable before it is declared.</p>
<p>Try to remove the //.</p>
<p id="demo"></p>
<script>
carName = "Volvo";
//const carName;
document.getElementById("demo").innerHTML = carName;
</script>
</body>
</html>
.ﺪﯿﻧﺍﻮﺨﺑ ﺮﺘﺸﯿﺑ JS Let/Const ﺭﺩ const ﻭ let ﻩﺭﺎﺑﺭﺩ
.ﻪﯿﻟﻭﺍ ﯽﻫﺩﺭﺍﺪﻘﻣ ﻪﻧ ،ﺪﻫﺩ ﯽﻣ ﺶﯾﺍﺰﻓﺍ ﺍﺭ ﺎﻫ ﻥﻼﻋﺍ ﻂﻘﻓ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ
1 ﻝﺎﺜﻣ ﺍﺭ ﻪﺠﯿﺘﻧ ﻥﺎﻤﻫ ﯽﻤﻧ ﺪﻫﺩ ﯽﻣ
var x = 5; // Initialize x
var y = 7; // Initialize y
elem = document.getElementById("demo"); // Find an element
elem.innerHTML = x + " " + y; // Display x and y
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var x = 5; // Initialize x
var y = 7; // Initialize y
elem = document.getElementById("demo"); // Find an element
elem.innerHTML = x + " " + y; // Display x and y
</script>
</body>
</html>
var x = 5; // Initialize x
elem = document.getElementById("demo"); // Find an element
elem.innerHTML = x + " " + y; // Display x and y
var y = 7; // Initialize y
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var x = 5; // Initialize x
elem = document.getElementById("demo"); // Find an element
elem.innerHTML = "x is " + x + " and y is " + y; // Display x and y
var y = 7; // Initialize y
</script>
</body>
</html>
؟ﺪﺷﺎﺑ ﻩﺪﺸﻧ ﻒﯾﺮﻌﺗ ﺮﺧﺁ ﻝﺎﺜﻣ ﺭﺩ y ﻪﮐ ﺖﺳﺍ ﯽﻘﻄﻨﻣ ﺎﯾﺁ
.ﺩﻭﺭ ﯽﻣ ﻻﺎﺑ ﻻﺎﺑ ﻪﺑ (7=) ﻪﯿﻟﻭﺍ ﯽﻫﺩ ﺭﺍﺪﻘﻣ ﻪﻧ ﻭ (var y) ﻥﻼﻋﺍ ﻂﻘﻓ ﻪﮐ ﺖﺳﺍ ﻞﯿﻟﺩ ﻦﯾﺍ ﻪﺑ ﻦﯾﺍ
ﻞﯿﻟﺩ ﻪﺑ ﺎﻣﺍ ،ﺖﺳﺍ ﻩﺪﺷ ﻡﻼﻋﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺯﺍ ﻞﺒﻗ y ،ﻥﺩﺮﺑ ﻻﺎﺑ ﻞﯿﻟﺩ ﻪﺑ
:ﺖﺳﺍ ﻦﺘﺷﻮﻧ ﺪﻨﻧﺎﻣ 2 ﻝﺎﺜﻣ
var x = 5; // Initialize x
var y; // Declare y
elem = document.getElementById("demo"); // Find an element
elem.innerHTML = x + " " + y; // Display x and y
y = 7; // Assign 7 to y
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var x = 5; // Initialize x
var y; // Declare y
elem = document.getElementById("demo"); // Find an element
elem.innerHTML = x + " " + y; // Display x and y
y = 7; // Assign 7 to y
</script>
</body>
</html>
ﺖﺳﺍ ﻩﺪﺷ ﻪﺘﻓﺮﮔ ﻩﺪﯾﺩﺎﻧ ﺎﯾ ﻪﺘﺧﺎﻨﺷﺎﻧ ﺭﺎﺘﻓﺭ ﮏﯾ (ﻥﺎﮔﺪﻨﻫﺩ ﻪﻌﺳﻮﺗ ﺯﺍ ﯼﺭﺎﯿﺴﺑ ﯼﺍﺮﺑ) ﻥﺩﺮﺑ ﻻﺎﺑ
<p>.ﺪﻨﺷﺎﺑ (ﺎﻄﺧ) ﺕﻻﺎﮑﺷﺍ ﯼﺍﺭﺍﺩ ﺎﻫﻪﻣﺎﻧﺮﺑ ﺖﺳﺍ ﻦﮑﻤﻣ ،ﺩﻮﺸﻧ ﻪﺟﻮﺘﻣ ﺍﺭ ﻥﺩﺮﺑ ﻻﺎﺑ ﻩﺪﻨﻫﺩ
ﺪﻧﻮﺷ ﻩﺩﺎﻔﺘﺳﺍ ﺎﻬﻧﺁ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺕﺭﻮﺻ ﺭﺩ ﺎﻫﺮﯿﻐﺘﻣ ﻪﮐ ﺪﻫﺩ ﯽﻤﻧ ﻩﺯﺎﺟﺍ ﺖﺨﺳ ﺖﻟﺎﺣ ﺭﺩ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎ