.ﻢﯿﻫﺩ ﺶﯾﺍﺰﻓﺍ ﺍﺭ ﺩﻮﺧ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫﺪﮐ ﺖﻋﺮﺳ ﻪﻧﻮﮕﭼ
.ﺪﻧﻮﺷ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﯽﺴﯾﻮﻧ ﻪﻣﺎﻧﺮﺑ ﺭﺩ ﺐﻠﻏﺍ ﺎﻫ ﻪﻘﻠﺣ
ﺩﻮﺷ ﯽﻣ ﺍﺮﺟﺍ ﻥﺁ ﺯﺍ ﺭﺍﺮﮑﺗ ﺮﻫ ﯼﺍﺮﺑ ،for ﺭﻮﺘﺳﺩ ﻪﻠﻤﺟ ﺯﺍ ،ﻪﻘﻠﺣ ﮏﯾ ﺭﺩ ﺭﻮﺘﺳﺩ ﺮﻫ
ﺪﻧﻮﺷ ﯽﻣ ﺚﻋﺎﺑ ،ﺪﻧﺮﯿﮔ ﺭﺍﺮﻗ ﻪﻘﻠﺣ ﺯﺍ ﺝﺭﺎﺧ ﺪﻨﻧﺍﻮﺗ ﯽﻣ ﻪﮐ ﯽﻔﯿﻟﺎﮑﺗ ﺎﯾ ﺕﺍﺭﺎﺒﻋ
for (let i = 0; i < arr.length; i++) {
let l = arr.length;
for (let i = 0; i < l; i++) {
ﺪﻨﮐ ﯽﻣ ﺍﺪﯿﭘ ﯽﺳﺮﺘﺳﺩ ﻪﯾﺍﺭﺁ ﮏﯾ length ﯽﮔﮋﯾﻭ ﻪﺑ ﺖﺳﺍ ﻪﻘﻠﺣ ﻪﮐ ﺭﺎﺑ ﺮﻫ ﺪﺑ ﺪﮐ
ﺩﺯﺎﺳ ﯽﻣ ﻭ ﺪﻨﮐ ﯽﻣ ﺍﺪﯿﭘ ﯽﺳﺮﺘﺳﺩ ﻪﻘﻠﺣ ﺯﺍ ﺝﺭﺎﺧ ﺭﺩ length ﯽﮔﮋﯾﻭ ﻪﺑ ﺮﺘﻬﺑ ﺪﮐ
.ﺖﺳﺍ ﺪﻨﮐ ﺭﺎﯿﺴﺑ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺕﺍﺭﺎﺒﻋ ﺮﮕﯾﺩ ﺎﺑ ﻪﺴﯾﺎﻘﻣ ﺭﺩ HTML DOM ﻪﺑ ﯽﺳﺮﺘﺳﺩ
ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﻭ ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﯽﺳﺮﺘﺳﺩ ﻥﺁ ﻪﺑ ﺭﺎﺑ ﮏﯾ ،ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﯽﺳﺮﺘﺳﺩ DOM ﺮﺼﻨﻋ ﮏﯾ ﻪﺑ ﺭﺎﺑ
const obj = document.getElementById("demo");
obj.innerHTML = "Hello";
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Performance</h2>
<p>If you expect to access a DOM element several times, access it once, and the use it as a local variable:</p>
<p id="demo"></p>
<script>
const obj = document.getElementById("demo");
obj.innerHTML = " Hello";
</script>
</body>
</html>
.ﺪﯾﺭﺍﺩ ﻪﮕﻧ ﻢﮐ ﺍﺭ HTML DOM ﺭﺩ ﺩﻮﺟﻮﻣ ﺮﺻﺎﻨﻋ ﺩﺍﺪﻌﺗ
ﺩﻮﺑ ﺪﻫﺍﻮﺧ ﻪﺸﯿﻤﻫ ﻦﯾﺍ
ﺩﻮﺑ ﺪﻫﺍﻮﺧ ﺪﯿﻔﻣ (getElementsByTagName ﺪﻨﻧﺎﻣ) DOM ﺭﺩ ﻮﺠﺘﺴﺟ ﯼﺍﺮﺑ ﯽﺷﻼﺗ ﺮﻫ
.ﺪﯿﻨﮑﻧ ﺩﺎﺠﯾﺍ ﯼﺪﯾﺪﺟ ﯼﺎﻫﺮﯿﻐﺘﻣ ،ﺪﯾﺭﺍﺪﻧ ﺍﺭ ﺮﯾﺩﺎﻘﻣ ﻥﺩﺮﮐ ﻩﺮﯿﺧﺫ ﺪﺼﻗ ﺮﮔﺍ
:ﺪﯿﻨﮐ ﻦﯾﺰﮕﯾﺎﺟ ﺍﺭ ﺮﯾﺯ ﯼﺎﻫﺪﮐ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ﺐﻠﻏﺍ
let fullName = firstName + " " + lastName;
document.getElementById("demo").innerHTML = fullName;
:ﻦﯾﺍ ﺎﺑ
document.getElementById("demo").innerHTML = firstName + " " + lastName;
ﺪﻨﮐ ﯼﺮﯿﮔﺭﺎﺑ ﺍﺭ ﻥﺁ ﺎﺗ ﺪﻫﺩ ﯽﻣ ﻩﺯﺎﺟﺍ ﺮﮔﺭﻭﺮﻣ ﻪﺑ ﻪﺤﻔﺻ ﻪﻧﺪﺑ ﻦﯿﯾﺎﭘ ﺭﺩ ﺩﻮﺧ ﯼﺎﻫ ﺖﭙﯾﺮﮑﺳﺍ ﻥﺩﺍﺩ ﺭ
ﺪﻨﮐ ﯽﻤﻧ ﻉﻭﺮﺷ ﺍﺭ ﯼﺮﮕﯾﺩ ﺖﭙﯾﺮﮑﺳﺍ ﭻﯿﻫ ﺮﮔﺭﻭﺮﻣ ،ﺖﺳﺍ ﺩﻮﻠﻧﺍﺩ ﻝﺎﺣ ﺭﺩ ﺖﭙﯾﺮﮑﺳﺍ ﮏﯾ ﻪﮐ ﯽﻟﺎﺣ ﺭﺩ
ﺪﻨﻨﮐ ﺩﻮﻠﻧﺍﺩ ﻥﺁ ﺯﺍ ﺮﺘﺸﯿﺑ ﺪﯾﺎﺒﻧ ﺎﻫﺮﮔﺭﻭﺮﻣ ﻪﮐ ﺪﻨﮐ ﯽﻣ ﻒﯾﺮﻌﺗ HTTP ﺕﺎﺼﺨﺸﻣ
ﺍﺭ .ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺖﭙﯾﺮﮑﺳﺍ ﮓﺗ ﺭﺩ defer="true"
ﺯﺍ ﻪﮐ ﺖﺳ
:ﺪﯿﻨﮐ ﻪﻓﺎﺿﺍ ﻪﺤﻔﺻ ﻪﺑ ﺪﮐ ﺎﺑ ﺍﺭ ﺩﻮﺧ ﺖﭙﯾﺮﮑﺳﺍ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ،ﻪﺤﻔﺻ ﯼﺭﺍﺬﮔﺭﺎﺑ ﺯﺍ ﺲﭘ ،ﻥﺎﮑﻣﺍ ﺕﺭﻮﺻ ﺭ
<script>
window.onload = function() {
const element = document.createElement("script");
element.src = "myScript.js";
document.body.appendChild(element);
};
</script>
ﯼﻭﺭ ﯽﻔﻨﻣ ﺮﯿﺛﺎﺗ .ﺪﯿﻨﮐ ﯼﺭﺍﺩﺩﻮﺧ ﺎﺑ<"code class="w3-codespan> ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ ﺯﺍ ﻩﺩﺎﻔﺘﺳ
.ﺖﺴﯿﻧ ﺯﺎﺠﻣ ﺖﺨﺳ ﺖﻟﺎﺣ ﺭﺩ ﺎﺑ<"code class="w3-codespan> ﯼﺪﯿﻠﮐ ﻪﻤﻠ