"use strict"؛
ﺪﻨﮐ ﯽﻣ ﻒﯾﺮﻌﺗ ﺍﺭ ﻦﯾﺍ
.ﺩﻮﺑ ﺪﯾﺪﺟ ECMAScript 5 ﻪﺨﺴﻧ ﺭﺩ "ﺖﺨﺳ ﻩﺩﺎﻔﺘﺳﺍ"<"code class="w3-codespan> ﻞﻤﻌﻟﺍﺭﻮ
ﺖﺳﺍ ﻩﺪﺷ ﻪﺘﻓﺮﮔ ﻩﺪﯾﺩﺎﻧ ﯽﻠﺒﻗ ﯼﺎﻫ ﻪﺨﺴﻧ ﻂﺳﻮﺗ ﻪﮐ ﺖﺳﺍ ﯽﻈﻔﻠﻟﺍ ﺖﺤﺗ ﺕﺭﺎﺒﻋ ﮏﯾ ﻪﮑﻠﺑ ،ﺖﺴﯿﻧ ﻪﯿﻧﺎﯿﺑ
.ﺩﻮﺷ ﺍﺮﺟﺍ "ﻖﯿﻗﺩ ﺖﻟﺎﺣ" ﺭﺩ ﺪﯾﺎﺑ ﺪﮐ ﺪﻫﺩ ﻥﺎﺸﻧ ﻪﮐ ﺖﺳﺍ ﻦﯾﺍ "ﺖﺨﺳ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ"<"code cl
.ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﻩﺪﺸﻧ ﻡﻼﻋﺍ ﯼﺎﻫﺮﯿﻐﺘﻣ ﺯﺍ ﺪﯿﻧﺍﻮﺗ ﯽﻤﻧ ،ﺖﺨﺳ ﺖﻟﺎﺣ ﺎﺑ ،ﻝﺎﺜﻣ ﯼﺍﺮﺑ
:ﺮﺗ ﻦﯿﯾﺎﭘ ﻭ Internet Explorer 9 ﺰﺟ ﻪﺑ ﺪﻨﻨﮐ ﯽﻣ ﯽﻧﺎﺒﯿﺘﺸﭘ "ﺖﺨﺳ ﻩﺩﺎﻔﺘﺳﺍ" ﺯﺍ ﻥﺭﺪﻣ ﯼﺎﻫﺮﮔﺭﻭﺮ
Directive | |||||
---|---|---|---|---|---|
"use strict" | 13.0 | 10.0 | 4.0 | 6.0 | 12.1 |
.ﺪﻨﮐ ﯽﻣ ﯽﻧﺎﺒﯿﺘﺸﭘ ﻞﻤﻌﻟﺍﺭﻮﺘﺳﺩ ﺯﺍ ﻞﻣﺎﮐ ﺭﻮﻃ ﻪﺑ ﻪﮐ ﺪﻨﮐ ﯽﻣ ﺺﺨﺸﻣ ﺍﺭ ﺮﮔﺭﻭﺮﻣ ﻪﺨﺴﻧ ﻦﯿﻟﻭﺍ ﻝﻭﺪﺟ ﺩ
،ﺪﯿﺴﯾﻮﻨﺑ ﯼﺮﺗ ﮎﺎﭘ ﺪﮐ ﺎﺗ ﺪﻨﮐ ﯽﻣ ﮏﻤﮐ ﺎﻤﺷ ﻪﺑ ﻦﯾﺍ .ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺩﻮﺧ ﯼﺎﻫ ﻪﻣﺎﻧﺮﺑ ﻪﻤﻫ ﺭﺩ ﺖﺨﺳ
"use strict"
ﻦﯾﺍﺮﺑﺎﻨﺑ ،ﺖﺳﺍ ﻪﺘﺷﺭ ﮏﯾ ﻂﻘﻓ IE 9 ﺪﻨﮐ ﯽﻤﻧ
.ﺩﻮﺷ ﯽﻣ ﻥﻼﻋﺍ ﮏﯾ ﯼﺍﺪﺘﺑﺍ ﻪﺑ "use strict"; ﻥﺩﻭﺰﻓﺍ ﺎﺑ ﺖﺨ
ﺎﻫﺪﮐ ﻪﻤﻫ) ﺖﺳﺍ ﯽﻧﺎﻬﺟ ﻪﻨﻣﺍﺩ ﯼﺍﺭﺍﺩ ،ﺖﭙﯾﺮﮑﺳﺍ ﮏﯾ ﯼﺍﺪﺘﺑﺍ ﺭﺩ ﻩﺪﺷ ﻡﻼﻋﺍ
"use strict";
x = 3.14; // This will cause an error
because x is not declared
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>With "use strict":</h2>
<h3>Using a variable without declaring it, is not allowed.</h3>
<p>Activate debugging in your browser (F12) to see the error report.</p>
<script>
"use strict";
x = 3.14; // This will cause an error (x is not defined).
</script>
</body>
</html>
"use strict";
myFunction();
function myFunction() {
y = 3.14; // This will also cause an error
because y is not declared
}
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>Global "use strict" declaration.</h2>
<p>Activate debugging in your browser (F12) to see the error report.</p>
<script>
"use strict";
myFunction();
function myFunction() {
y = 3.14; // This will cause an error (y is not defined)
}
</script>
</body>
</html>
ﺖﺳﺍ ﻊﺑﺎﺗ ﻞﺧﺍﺩ ﺪﮐ ﻂﻘﻓ) ﺖﺳﺍ ﯽﻠﺤﻣ ﻩﺩﻭﺪﺤﻣ ﯼﺍﺭﺍﺩ ،ﺩﻮﺷ ﯽﻣ ﻥﻼﻋﺍ ﻊﺑﺎﺗ ﮏﯾ ﻞﺧﺍﺩ ﺭﺩ ﻪﮐ
x = 3.14; // This will not cause an error.
myFunction();
function
myFunction() {
"use strict";
y = 3.14; // This will cause an error
}
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<p>"use strict" in a function will only cause errors in that function.</p>
<p>Activate debugging in your browser (F12) to see the error report.</p>
<script>
x = 3.14; // This will not cause an error.
myFunction();
function myFunction() {
"use strict";
y = 3.14; // This will cause an error (y is not defined).
}
</script>
</body>
</html>
ﺪﺷﺎﺑ ﺭﺎﮔﺯﺎﺳ ﻥﺁ ﺎﺑ ﻪﮐ ﺖﺳﺍ ﻩﺪﺷ ﯽﺣﺍﺮﻃ ،ﺖﺨﺳ ﺖﻟﺎﺣ ﻡﻼﻋﺍ ﯼﺍﺮﺑ ،ﻮﺤﻧ
ﮏﯾ ﺭﺩ (؛"ﻭﺩ ﻥﺎﺟ") ﯼﺍ ﻪﺘﺷﺭ ﻆﻔﻟ ﮏﯾ ﺎﯾ (;5 + 4) ﯼﺩﺪﻋ ﻆﻔﻟ ﮏﯾ ﻞﯾﺎﭙﻣﺎﮐ
.ﺖﺳﺍ ﻢﻬﻣ ﺪﻧﺭﺍﺩ "ﮎﺭﺩ" ﺍﺭ ﯽﻨﻌﻣ ﻪﮐ ﯼﺪﯾﺪﺟ ﯼﺎﻫﺮﻠﯾﺎﭙﻣﺎﮐ ﯼﺍﺮﺑ ﻂﻘﻓ ؛"ﺖﺨﺳ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ"<"
.ﺪﻨﮐ ﯽﻣ ﺮﺗ ﻥﺎﺳﺁ ﺍﺭ "ﻦﻣﺍ" ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻦﺘﺷﻮﻧ ﻪﻧﺍﺮﯿﮕﺘﺨﺳ ﺖﻟﺎﺣ
.ﺪﻫﺩ ﯽﻣ ﺮﯿﯿﻐﺗ ﯽﻌﻗﺍﻭ ﯼﺎﻫﺎﻄﺧ ﻪﺑ ﺩﻮﺑ ﻩﺪﺷ ﻪﺘﻓﺮﯾﺬﭘ ﻼﺒﻗ ﻪﮐ ﺍﺭ "ﺪﺑ ﻮﺤﻧ " ﻪﻧﺍﺮﯿﮔ ﺖﺨﺳ ﺖﻟﺎﺣ
ﺪﻨﮐ ﯽﻣ ﺩﺎﺠﯾﺍ ﺪﯾﺪﺟ ﻡﺎﻧ ﮏﯾ ،ﺮﯿﻐﺘﻣ ﻡﺎﻧ ﻩﺎﺒﺘﺷﺍ ﭗﯾﺎﺗ ،ﯽﻟﻮﻤﻌﻣ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺭﺩ ،ﻝﺎﺜﻣ ﻥﺍﻮﻨﻋ ﻪ
ﺪﻨﮐﯽﻤﻧ ﺖﻓﺎﯾﺭﺩ ﯽﯾﺎﻄﺧ ﺩﺭﻮﺧﺯﺎﺑ ﭻﯿﻫ ﺲﯾﻮﻧﻪﻣﺎﻧﺮﺑ ،ﯽﻟﻮﻤﻌﻣ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺭﺩ
ﻩﺪﻧﺮﯿﮔ ﮏﯾ ﻂﻘﻓ ،ﻦﺘﺷﻮﻧ ﻞﺑﺎﻗﺮﯿﻏ ﯽﮔﮋﯾﻭ ﮏﯾ ﻪﺑ ﺏﺎﺴﺘﻧﺍ ﺮﻫ ،ﺖﺨﺳ ﺖﻟﺎﺣ ﺭﺩ
:ﺖﺴﯿﻧ ﺯﺎﺠﻣ ﻥﺁ ﻥﻼﻋﺍ ﻥﻭﺪﺑ ﺮﯿﻐﺘﻣ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ
"use strict";
x = 3.14; // This will cause an error
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>With "use strict":</h2>
<h3>Using a variable without declaring it, is not allowed.</h3>
<p>Activate debugging in your browser (F12) to see the error report.</p>
<script>
"use strict";
x = 3.14; // This will cause an error (x is not defined).
</script>
</body>
</html>
.ﺪﻨﺘﺴﻫ ﺮﯿﻐﺘﻣ ﺰﯿﻧ ﺎﯿﺷﺍ
:ﺖﺴﯿﻧ ﺯﺎﺠﻣ ،ﻥﺁ ﻡﻼﻋﺍ ﻥﻭﺪﺑ ،ﯽﺷ ﮏﯾ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ
"use strict";
x = {p1:10, p2:20}; // This will cause an error
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>With "use strict":</h2>
<h3>Using an object without declaring it, is not allowed.</h3>
<p>Activate debugging in your browser (F12) to see the error report.</p>
<script>
"use strict";
x = {p1:10, p2:20}; // This will cause an error (x is not defined).
</script>
</body>
</html>
.ﺖﺴﯿﻧ ﺯﺎﺠﻣ (ﯽﺷ ﺎﯾ) ﺮﯿﻐﺘﻣ ﮏﯾ ﻑﺬﺣ
"use strict";
let x = 3.14;
delete x; // This
will cause an error
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>With "use strict":</h2>
<h3>Deleting a variable (or object) is not allowed.</h3>
<p>Activate debugging in your browser (F12) to see the error report.</p>
<script>
"use strict";
let x = 3.14;
delete x; // This will cause an error
</script>
</body>
</html>
.ﺖﺴﯿﻧ ﺯﺎﺠﻣ ﻊﺑﺎﺗ ﮏﯾ ﻑﺬﺣ
"use strict";
function x(p1, p2) {};
delete x;
// This will cause an error
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>With "use strict":</h2>
<h3>Deleting a function is not allowed.</h3>
<p>Activate debugging in your browser (F12) to see the error report.</p>
<script>
"use strict";
function x(p1, p2) {};
delete x; // This will cause an error
</script>
</body>
</html>
:ﺖﺴﯿﻧ ﺯﺎﺠﻣ ﺮﺘﻣﺍﺭﺎﭘ ﻡﺎﻧ ﻥﺩﺮﮐ ﯽﭙﮐ
"use strict";
function x(p1, p1) {}; // This will cause an error
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>With "use strict":</h2>
<h3>Duplicating a parameter name is not allowed.</h3>
<p>Activate debugging in your browser (F12) to see the error report.</p>
<script>
"use strict";
function x(p1, p1) {}; // This will cause an error
</script>
</body>
</html>
:ﺪﻨﺘﺴﯿﻧ ﺯﺎﺠﻣ ﻪﻧﺎﮕﺘﺸﻫ ﺩﺍﺪﻋﺍ ﻑﻭﺮﺣ
"use strict";
let x = 010; // This
will cause an error
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>With "use strict":</h2>
<h3>Octal numeric literals are not allowed.</h3>
<p>Activate debugging in your browser (F12) to see the error report.</p>
<script>
"use strict";
let x = 010; // This will cause an error
</script>
</body>
</html>
:ﺪﻨﺘﺴﯿﻧ ﺯﺎﺠﻣ ﻪﻧﺎﮕﺘﺸﻫ ﺭﺍﺮﻓ ﯼﺎﻫﺮﺘﮐﺍﺭﺎﮐ
"use strict";
let x = "\010"; // This will cause an error
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>With "use strict":</h2>
<h3>Octal escape characters are not allowed.</h3>
<p>Activate debugging in your browser (F12) to see the error report.</p>
<script>
"use strict";
let x = "\010"; // This will cause an error
</script>
</body>
</html>
:ﺖﺴﯿﻧ ﺯﺎﺠﻣ ﯽﻧﺪﻧﺍﻮﺧ ﻂﻘﻓ ﯽﮔﮋﯾﻭ ﮏﯾ ﺭﺩ ﻦﺘﺷﻮﻧ
"use strict";
const obj = {};
Object.defineProperty(obj, "x", {value:0, writable:false});
obj.x = 3.14; // This
will cause an error
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>With "use strict":</h2>
<h3>Writing to a read-only property is not allowed.</h3>
<p>Activate debugging in your browser (F12) to see the error report.</p>
<script>
"use strict";
const obj = {};
Object.defineProperty(obj, "x", {value:0, writable:false});
obj.x = 3.14; // This will cause an error
</script>
</body>
</html>
:ﺖﺴﯿﻧ ﺯﺎﺠﻣ ﯽﺘﻓﺎﯾﺭﺩ ﻂﻘﻓ ﯽﯾﺍﺭﺍﺩ ﮏﯾ ﻪﺑ ﻦﺘﺷﻮﻧ
"use strict";
const obj = {get x()
{return 0} };
obj.x = 3.14; // This
will cause an error
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>With "use strict":</h2>
<h3>Writing to a get-only property is not allowed.</h3>
<p>Activate debugging in your browser (F12) to see the error report.</p>
<script>
"use strict";
const obj = {get x() {return 0} };
obj.x = 3.14; // This will cause an error
</script>
</body>
</html>
:ﺖﺴﯿﻧ ﺯﺎﺠﻣ ﻑﺬﺣ ﻞﺑﺎﻗﺮﯿﻏ ﯽﮔﮋﯾﻭ ﮏﯾ ﻑﺬﺣ
"use strict";
delete Object.prototype; // This will cause an error
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>With "use strict":</h2>
<h3>Deleting an udeletable property is not allowed.</h3>
<p>Activate debugging in your browser (F12) to see the error report.</p>
<script>
"use strict";
delete Object.prototype; // This will cause an error
</script>
</body>
</html>
:ﺩﺮﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺮﯿﻐﺘﻣ ﮏﯾ ﻥﺍﻮﻨﻋ ﻪﺑ ﻥﺍﻮﺗ ﯽﻤﻧ ﺍﺭ eval
ﻪﻤﻠﮐ
"use strict";
let eval = 3.14; // This will cause an error
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>With "use strict":</h2>
<h3>The string "eval" cannot be used as a variable.</h3>
<p>Activate debugging in your browser (F12) to see the error report.</p>
<script>
"use strict";
let eval = 3.14; // This will cause an error
</script>
</body>
</html>
:ﺩﺮﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺮﯿﻐﺘﻣ ﮏﯾ ﻥﺍﻮﻨﻋ ﻪﺑ ﻥﺍﻮﺗ ﯽﻤﻧ ﺍﺭ arguments
"use strict";
let arguments = 3.14; // This will cause an error
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>With "use strict":</h2>
<h3>The string "arguments" cannot be used as a variable.</h3>
<p>Activate debugging in your browser (F12) to see the error report.</p>
<script>
"use strict";
let arguments = 3.14; // This will cause an error
</script>
</body>
</html>
:ﺖﺴﯿﻧ ﺯﺎﺠﻣ with
ﺕﺭﺎﺒﻋ
"use strict";
with (Math){x = cos(2)}; // This will cause an error
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>With "use strict":</h2>
<h3>The with statement is not allowed.</h3>
<p>Activate debugging in your browser (F12) to see the error report.</p>
<script>
"use strict";
with (Math){x = cos(2)}; // This will cause an error
</script>
</body>
</html>
ﺩﺭﺍﺪﻧ ﺩﺎﺠﯾﺍ ﻩﺯﺎﺟﺍ eval()
،ﯽﺘﯿﻨﻣﺍ ﻞﯾﻻﺩ ﻪﺑ
:ﺩﺮﮐ ﻩﺩﺎﻔﺘﺳﺍ ﻡﻼﻋﺍ ﺯﺍ ﻞﺒﻗ ﻥﺍﻮﺗ ﯽﻤﻧ ﺍﺭ ﺮﯿﻐﺘﻣ ﮏﯾ ،ﺖﺨﺳ ﺖﻟﺎﺣ ﺭﺩ
"use strict";
eval ("x = 2");
alert (x); // This
will cause an error
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>With "use strict":</h2>
<h3>For security reasons, eval() is not allowed to create variables in the scope from which it was called.</h3>
<p>Activate debugging in your browser (F12) to see the error report.</p>
<script>
"use strict";
eval ("x = 2");
alert (x); // This will cause an error
</script>
</body>
</html>
:ﺪﻨﮐ ﻡﻼﻋﺍ var ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺎﺑ ﺍﺭ ﺮﯿﻐﺘﻣ ﮏﯾ ﺪﻧﺍﻮﺗ ﯽﻤﻧ()eval ،ﺖﺨﺳ ﺖﻟﺎﺣ ﺭﺩ
"use strict";
eval ("var x = 2");
alert (x); // This
will cause an error
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>With "use strict":</h2>
<h3>For security reasons, eval() is not allowed to create variables in the scope from which it was called.</h3>
<p>Activate debugging in your browser (F12) to see the error report.</p>
<script>
"use strict";
eval ("var x = 2");
alert (x); // This will cause an error
</script>
</body>
</html>
() eval ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺎﺑ ﺍﺭ ﺮﯿﻐﺘﻣ ﮏﯾ ﺪﻧﺍﻮﺗ ﯽﻤﻧ let ﺪﻨﮐ ﻥﻼﻋﺍ:
eval ("let x = 2");
alert (x); // This
will cause an error
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>Using eval()</h2>
<h3>For security reasons, eval() is not allowed to create variables in the scope from which it was called.</h3>
<p>Activate debugging in your browser (F12) to see the error report.</p>
<script>
eval ("let x = 2");
alert (x); // This will cause an error
</script>
</body>
</html>
ﺪﻨﮐ ﯽﻣ ﺭﺎﺘﻓﺭ ﻊﺑﺍﻮﺗ ﺭﺩ ﻦﯾﺍ<"code class="w3-codespan> ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ
ﻪﮐ ﺩﺭﺍﺩ ﻩﺭﺎﺷﺍ ﯽﺌﯿﺷ ﻪﺑ this
ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ
ﺪﻨﮐ ﯽﻣ ﺭﺎﮐ ﺖﺨﺳ ﺖﻟﺎﺣ ﺭﺩ ،ﺪﺷﺎﺑ ﻩﺪﺸﻧ ﺺﺨﺸﻣ ﯽﺷ ﺮﮔﺍ
"use strict";
function myFunction() {
alert(this); // will alert "undefined"
}
myFunction();
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>With "use strict":</h2>
<h3>Inside functions, the "this" keyword is no longer the global object if not specified:</h3>
<script>
"use strict";
function myFunction() {
alert(this);
}
myFunction();
</script>
</body>
</html>
ﺩﺮﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺮﯿﻐﺘﻣ ﻥﺍﻮﻨﻋ ﻪﺑ ﻥﺍﻮﺗ ﯽﻤﻧ ﺍﺭ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﺗﺁ ﯼﺎﻫ ﻪﺨﺴﻧ ﯼﺍﺮﺑ ﻩﺪﺷ ﻭﺭﺯﺭ ﯼﺪﯿﻠﮐ
:ﺪﻨﺘﺴﻫ ﺎﻬﻨﯾﺍ
"use strict";
let public = 1500; // This will cause an error
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>With "use strict":</h2>
<h3>Future reserved keywords are not allowed in strict mode.</h3>
<p>Activate debugging in your browser (F12) to see the error report.</p>
<script>
"use strict";
let public = 1500; // This will cause an error
</script>
</body>
</html>
ﺩﻮﺷ ﯽﻣ ﻪﺘﺧﺎﻨﺷ ﺖﭙﯾﺮﮑﺳﺍ ﮏﯾ ﺍﺪﺘﺑﺍ ﺭﺩ ﻂﻘﻓ "ﺖﺨﺳ ﻩﺩﺎﻔﺘﺳﺍ" ﻞﻤﻌﻟﺍﺭﻮﺘﺳﺩ