From 1d59c6ce498c7ae9f3c5f80ff9f8b94f63431d65 Mon Sep 17 00:00:00 2001 From: MaHdi Date: Tue, 5 Oct 2021 19:55:17 +0330 Subject: [PATCH 1/9] Replace whole article with English version Some lines were duplicate and I found out that the article has "old/new parts", and since it's not translated I decided to just replace it. --- 1-js/06-advanced-functions/04-var/article.md | 32 +++++++------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/1-js/06-advanced-functions/04-var/article.md b/1-js/06-advanced-functions/04-var/article.md index 3211fa484..cade0147f 100644 --- a/1-js/06-advanced-functions/04-var/article.md +++ b/1-js/06-advanced-functions/04-var/article.md @@ -13,13 +13,7 @@ In the very first chapter about [variables](info:variables), we mentioned three 2. `const` 3. `var` -`let` and `const` behave exactly the same way in terms of Lexical Environments. - -But `var` is a very different beast, that originates from very old times. It's generally not used in modern scripts, but still lurks in the old ones. - -If you don't plan meeting such scripts you may even skip this chapter or postpone it, but then there's a chance that it bites you later. - -From the first sight, `var` behaves similar to `let`. That is, declares a variable: +The `var` declaration is similar to `let`. Most of the time we can replace `let` by `var` or vice-versa and expect things to work: ```js run var message = "Hi"; @@ -38,7 +32,7 @@ Variables, declared with `var`, are either function-scoped or global-scoped. The For instance: -```js +```js run if (true) { var test = true; // use "var" instead of "let" } @@ -48,11 +42,6 @@ alert(test); // true, the variable lives after if */!* ``` -@@@needs translation@@@ -@@@old part@@@ -If we used `let test` on the 2nd line, then it wouldn't be visible to `alert`. But `var` ignores code blocks, so we've got a global `test`. -@@@old part@@@ -@@@new part@@@ As `var` ignores code blocks, we've got a global variable `test`. If we used `let test` instead of `var test`, then the variable would only be visible inside `if`: @@ -66,8 +55,6 @@ if (true) { alert(test); // ReferenceError: test is not defined */!* ``` -@@@new part@@@ -@@@needs translation@@@ The same thing for loops: `var` cannot be block- or loop-local: @@ -85,7 +72,7 @@ alert(one); // 1, "one" is visible after loop, it's a global variable If a code block is inside a function, then `var` becomes a function-level variable: -```js +```js run function sayHi() { if (true) { var phrase = "Hello"; @@ -128,7 +115,7 @@ In other words, `var` variables are defined from the beginning of the function, So this code: -```js +```js run function sayHi() { phrase = "Hello"; @@ -138,11 +125,12 @@ function sayHi() { var phrase; */!* } +sayHi(); ``` ...Is technically the same as this (moved `var phrase` above): -```js +```js run function sayHi() { *!* var phrase; @@ -152,11 +140,12 @@ function sayHi() { alert(phrase); } +sayHi(); ``` ...Or even as this (remember, code blocks are ignored): -```js +```js run function sayHi() { phrase = "Hello"; // (*) @@ -168,6 +157,7 @@ function sayHi() { alert(phrase); } +sayHi(); ``` People also call such behavior "hoisting" (raising), because all `var` are "hoisted" (raised) to the top of the function. @@ -287,11 +277,11 @@ In all the above cases we declare a Function Expression and run it immediately. ## Summary -There are two main differences of `var`: +There are two main differences of `var` compared to `let/const`: 1. `var` variables have no block scope, their visibility is scoped to current function, or global, if declared outside function. 2. `var` declarations are processed at function start (script start for globals). There's one more very minor difference related to the global object, that we'll cover in the next chapter. -These differences are actually a bad thing most of the time. First, we can't create block-local variables. And hoisting just creates more space for errors. So, for new scripts `var` is used exceptionally rarely. +These differences make `var` worse than `let` most of the time. Block-level variables is such a great thing. That's why `let` was introduced in the standard long ago, and is now a major way (along with `const`) to declare a variable. From f36050a38a43d01e54d7dfefcedc4646fe77289a Mon Sep 17 00:00:00 2001 From: MaHdi Date: Wed, 6 Oct 2021 09:25:35 +0330 Subject: [PATCH 2/9] Translate a part of article --- 1-js/06-advanced-functions/04-var/article.md | 22 ++++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/1-js/06-advanced-functions/04-var/article.md b/1-js/06-advanced-functions/04-var/article.md index cade0147f..4bd1a04f3 100644 --- a/1-js/06-advanced-functions/04-var/article.md +++ b/1-js/06-advanced-functions/04-var/article.md @@ -1,30 +1,30 @@ -# The old "var" +# کلمه "var" قدیمی -```smart header="This article is for understanding old scripts" -The information in this article is useful for understanding old scripts. +```smart header="این مقاله برای فهمیدن اسکریپت‌های قدیمی است" +اطلاعات این مقاله برای فهمیدن اسکریپت‌های قدیمی مفید است. -That's not how we write new code. +ما کدهای جدید را اینگونه نمی‌نویسیم. ``` -In the very first chapter about [variables](info:variables), we mentioned three ways of variable declaration: +دقیقا در فصل اول درباره [متغیرها](info:variables)، ما سه راه تعریف متغیر را معرفی کردیم: 1. `let` 2. `const` 3. `var` -The `var` declaration is similar to `let`. Most of the time we can replace `let` by `var` or vice-versa and expect things to work: +تعریف متغیر توسط `var` مانند `let` است. اکثر اوقات ما می‌توانیم `let` را با `var` جایگزین کنیم یا برعکس و توقع داشته باشیم که دستورات کار کنند: ```js run -var message = "Hi"; -alert(message); // Hi +var message = "سلام"; +alert(message); // سلام ``` -But internally `var` is a very different beast, that originates from very old times. It's generally not used in modern scripts, but still lurks in the old ones. +اما از دورن، `var` گونه‌ای بسیار متفاوت است که از زمان‌های قدیم وجود دارد. به طور کلی در اسکریپت‌های جدید استفاده نمی‌شود ولی هنوز هم در اسکریپت‌های قدیمی کمین کرده است. -If you don't plan on meeting such scripts you may even skip this chapter or postpone it. +اگر شما قرار نیست چنین اسکریپت‌هایی را ببینید می‌توانید این فصل را رد کنید یا مطالعه آن را به عقب بندازید. -On the other hand, it's important to understand differences when migrating old scripts from `var` to `let`, to avoid odd errors. +از سویی دیگر، زمانی که اسکریپت‌های قدیمی را از `var` به `let` کوچ می‌دهیم، دانستن تفاوت‎ها برای جلوگیری از ارورهای عجیب مهم است. ## "var" has no block scope From 38ff899c302f2df9535332d358caf46cbab6b5bc Mon Sep 17 00:00:00 2001 From: MaHdi Date: Thu, 7 Oct 2021 13:12:17 +0330 Subject: [PATCH 3/9] Translate a part of article --- 1-js/06-advanced-functions/04-var/article.md | 30 ++++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/1-js/06-advanced-functions/04-var/article.md b/1-js/06-advanced-functions/04-var/article.md index 4bd1a04f3..d46d99a4e 100644 --- a/1-js/06-advanced-functions/04-var/article.md +++ b/1-js/06-advanced-functions/04-var/article.md @@ -26,29 +26,29 @@ alert(message); // سلام از سویی دیگر، زمانی که اسکریپت‌های قدیمی را از `var` به `let` کوچ می‌دهیم، دانستن تفاوت‎ها برای جلوگیری از ارورهای عجیب مهم است. -## "var" has no block scope +## کلمه "var" محدوده بلوک ندارد -Variables, declared with `var`, are either function-scoped or global-scoped. They are visible through blocks. +متغیرهایی که با `var` تعریف شده‌اند، یا محدوده تابع دارند یا محدوده گلوبال. آن‌ها در این بلوک‌ها قابل رویت هستند. -For instance: +برای مثال: ```js run if (true) { - var test = true; // use "var" instead of "let" + var test = true; // استفاده کنید "var" از "let" به جای } *!* -alert(test); // true, the variable lives after if +alert(test); // true ،هم باقی می‌ماند if متغیر بعد از */!* ``` -As `var` ignores code blocks, we've got a global variable `test`. +چون `var` بلوک‌های کد را نادیده می‌گیرد، ما یک متغیر گلوبال `test` خواهیم داشت. -If we used `let test` instead of `var test`, then the variable would only be visible inside `if`: +اگر ما به جای `var test` از `let test` استفاده می‌کردیم، سپس متغیر فقط درون `if` قابل رویت بود: ```js run if (true) { - let test = true; // use "let" + let test = true; // "let" استفاده از } *!* @@ -56,7 +56,7 @@ alert(test); // ReferenceError: test is not defined */!* ``` -The same thing for loops: `var` cannot be block- or loop-local: +همین مورد برای حلقه‌ها هم صدق می‌کند: `var` نمی‌تواند در محدوده بلوک حلقه باشد: ```js for (var i = 0; i < 10; i++) { @@ -65,27 +65,27 @@ for (var i = 0; i < 10; i++) { } *!* -alert(i); // 10, "i" is visible after loop, it's a global variable -alert(one); // 1, "one" is visible after loop, it's a global variable +alert(i); // 10 ،بعد از حلقه قابل رویت است چون یک متغیر گلوبال است "i" +alert(one); // 1 ،بعد از حلقه قابل رویت است چون یک متغیر گلوبال است "one" */!* ``` -If a code block is inside a function, then `var` becomes a function-level variable: +اگر یک بلوک کد درون تابع باشد، سپس `var` یک متغیر در سطح تابع می‌شود: ```js run function sayHi() { if (true) { - var phrase = "Hello"; + var phrase = "سلام"; } - alert(phrase); // works + alert(phrase); // کار می‌کند } sayHi(); alert(phrase); // ReferenceError: phrase is not defined ``` -As we can see, `var` pierces through `if`, `for` or other code blocks. That's because a long time ago in JavaScript, blocks had no Lexical Environments, and `var` is a remnant of that. +همانطور که می‌بینیم، `var` از درون `if`، `for` یا بقیه بلوک‌های کد بیرون می‌آید. به این دلیل که در زمان‌های قدیم، بلوک‌ها در جاوااسکریپت محیط‌های لغوی نداشتند و `var` یک باقی‌مانده از آن است. ## "var" tolerates redeclarations From dd64bde423b536df0ff0bf10bb17b7382a0ac883 Mon Sep 17 00:00:00 2001 From: MaHdi Date: Thu, 7 Oct 2021 13:19:25 +0330 Subject: [PATCH 4/9] Translate a part of article --- 1-js/06-advanced-functions/04-var/article.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/1-js/06-advanced-functions/04-var/article.md b/1-js/06-advanced-functions/04-var/article.md index d46d99a4e..44d4788be 100644 --- a/1-js/06-advanced-functions/04-var/article.md +++ b/1-js/06-advanced-functions/04-var/article.md @@ -87,22 +87,22 @@ alert(phrase); // ReferenceError: phrase is not defined همانطور که می‌بینیم، `var` از درون `if`، `for` یا بقیه بلوک‌های کد بیرون می‌آید. به این دلیل که در زمان‌های قدیم، بلوک‌ها در جاوااسکریپت محیط‌های لغوی نداشتند و `var` یک باقی‌مانده از آن است. -## "var" tolerates redeclarations +## کلمه "var" تعریف‌های دوباره را تحمل می‌کند -If we declare the same variable with `let` twice in the same scope, that's an error: +اگر ما با `let` متغیری یکسان را دوبار در محدوده بلوک یکسان تعریف کنیم، یک ارور ایجاد می‌شود: ```js run let user; let user; // SyntaxError: 'user' has already been declared ``` -With `var`, we can redeclare a variable any number of times. If we use `var` with an already-declared variable, it's just ignored: +با `var` ما می‌توانیم یک متغیر را هر چند بار که بخواهیم دوباره تعریف کنیم. اگر ما از `var` همراه با یک متغیر از قبل تعریف شده استفاده کنیم، نادیده گرفته می‌شود: ```js run var user = "Pete"; -var user = "John"; // this "var" does nothing (already declared) -// ...it doesn't trigger an error +var user = "John"; // کاری انجام نمی‌دهد (از قبل تعریف شده) "var" این +// ...اروری ایجاد نمی‌کند alert(user); // John ``` From a6bbd2a1171824c293efc16e5d35d6c64b06a6e8 Mon Sep 17 00:00:00 2001 From: MaHdi Date: Fri, 8 Oct 2021 16:31:24 +0330 Subject: [PATCH 5/9] Change a word for better understanding --- 1-js/06-advanced-functions/04-var/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/06-advanced-functions/04-var/article.md b/1-js/06-advanced-functions/04-var/article.md index 44d4788be..4b6842717 100644 --- a/1-js/06-advanced-functions/04-var/article.md +++ b/1-js/06-advanced-functions/04-var/article.md @@ -87,7 +87,7 @@ alert(phrase); // ReferenceError: phrase is not defined همانطور که می‌بینیم، `var` از درون `if`، `for` یا بقیه بلوک‌های کد بیرون می‌آید. به این دلیل که در زمان‌های قدیم، بلوک‌ها در جاوااسکریپت محیط‌های لغوی نداشتند و `var` یک باقی‌مانده از آن است. -## کلمه "var" تعریف‌های دوباره را تحمل می‌کند +## کلمه "var" تعریف‌های دوباره را قبول می‌کند اگر ما با `let` متغیری یکسان را دوبار در محدوده بلوک یکسان تعریف کنیم، یک ارور ایجاد می‌شود: From d07c051fa295eb6455d1dbf9d724cc55dbd509cb Mon Sep 17 00:00:00 2001 From: MaHdi Date: Fri, 8 Oct 2021 19:02:33 +0330 Subject: [PATCH 6/9] Translate a part of article --- 1-js/06-advanced-functions/04-var/article.md | 44 ++++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/1-js/06-advanced-functions/04-var/article.md b/1-js/06-advanced-functions/04-var/article.md index 4b6842717..80ebf7360 100644 --- a/1-js/06-advanced-functions/04-var/article.md +++ b/1-js/06-advanced-functions/04-var/article.md @@ -107,17 +107,17 @@ var user = "John"; // کاری انجام نمی‌دهد (از قبل تعری alert(user); // John ``` -## "var" variables can be declared below their use +## متغیرهای "var" می‌توانند پایین محل استفاده‌شان تعریف شوند -`var` declarations are processed when the function starts (or script starts for globals). +متغیرهای تعریف شده با `var` زمانی که اجرای تابع شروع می‌شود (یا برای متغیرهای گلوبال زمانی که اسکریپت شروع می‌شود) پردازش می‌شوند. -In other words, `var` variables are defined from the beginning of the function, no matter where the definition is (assuming that the definition is not in the nested function). +به عبارتی دیگر، متغیرهای `var` بدون توجه به محل تعریف آن‌ها، از زمانی که اجرای تابع شروع می‌شود تعریف می‌شوند (با فرض اینکه تعریف کردن درون تابع تودرتو نیست). -So this code: +پس این کد: ```js run function sayHi() { - phrase = "Hello"; + phrase = "سلام"; alert(phrase); @@ -128,7 +128,7 @@ function sayHi() { sayHi(); ``` -...Is technically the same as this (moved `var phrase` above): +...از لحاظ فنی با این کد برابر است (عبارت `var phrase` را بالا بردیم): ```js run function sayHi() { @@ -136,18 +136,18 @@ function sayHi() { var phrase; */!* - phrase = "Hello"; + phrase = "سلام"; alert(phrase); } sayHi(); ``` -...Or even as this (remember, code blocks are ignored): +...حتی با این هم برابر است (به یاد داشته باشید که بلوک‌های کد نادیده گرفته می‌شوند): ```js run function sayHi() { - phrase = "Hello"; // (*) + phrase = "سلام"; // (*) *!* if (false) { @@ -160,52 +160,52 @@ function sayHi() { sayHi(); ``` -People also call such behavior "hoisting" (raising), because all `var` are "hoisted" (raised) to the top of the function. +افراد به آن «بالا بردن» هم می‌گویند چون تمام `var`ها به بالای تابع «سعود می‌کنند». -So in the example above, `if (false)` branch never executes, but that doesn't matter. The `var` inside it is processed in the beginning of the function, so at the moment of `(*)` the variable exists. +پس در مثال بالا، شاخه `if (false)` هیچوقت اجرا نمی‌شود اما اصلا مهم نیست. `var` که درون آن است در ابتدای اجرای تابع پردازش می‌شود پس هنگام اجرای `(*)` متغیر وجود دارد. -**Declarations are hoisted, but assignments are not.** +**تعریف متغیر بالا می‌رود اما مقداردهی‌ها نه.** -That's best demonstrated with an example: +این موضوع یک مثال بهتر نمایش داده می‌شود: ```js run function sayHi() { alert(phrase); *!* - var phrase = "Hello"; + var phrase = "سلام"; */!* } sayHi(); ``` -The line `var phrase = "Hello"` has two actions in it: +خط `var phrase = "سلام"` در خودش دو کار انجام می‌دهد: -1. Variable declaration `var` -2. Variable assignment `=`. +1. تعریف متغیر با `var`. +2. مقداردهی متغیر با `=`. -The declaration is processed at the start of function execution ("hoisted"), but the assignment always works at the place where it appears. So the code works essentially like this: +تعریف متغیر در ابتدای اجرای تابع پردازش می‌شود («بالا می‌رود») اما مقداردهی همیشه در جایی که وجود دارد انجام می‌شود. پس کد بالا اساسا مانند کد پایین کار می‌کند: ```js run function sayHi() { *!* - var phrase; // declaration works at the start... + var phrase; // ...تعریف متغیر در ابتدا انجام می‌شود */!* alert(phrase); // undefined *!* - phrase = "Hello"; // ...assignment - when the execution reaches it. + phrase = "Hello"; // ...مقداردهی - زمانی که اجرا به آن می‌رسد */!* } sayHi(); ``` -Because all `var` declarations are processed at the function start, we can reference them at any place. But variables are undefined until the assignments. +چون تمام تعریف متغیرهای `var` در ابتدای تابع پردازش می‌شوند، ما می‌توانیم به آن‌ها در هر زمانی رجوع کنیم. اما متغیرها تا زمان مقداردهی برابر با undefined هستند. -In both examples above, `alert` runs without an error, because the variable `phrase` exists. But its value is not yet assigned, so it shows `undefined`. +در هر دو مثال بالا، `alert` بدون هیچ اروری اجرا می‌شود چون متغیر `phrase` وجود دارد. اما مقدار آن هنوز تخصیص داده نشده است پس `undefined` را نشان می‌شود. ## IIFE From 4682926f0e8ccf7db23095d8fb8b12ba5db7d57b Mon Sep 17 00:00:00 2001 From: MaHdi Date: Sat, 9 Oct 2021 13:17:31 +0330 Subject: [PATCH 7/9] Translate article Last line needs a more attention --- 1-js/06-advanced-functions/04-var/article.md | 56 ++++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/1-js/06-advanced-functions/04-var/article.md b/1-js/06-advanced-functions/04-var/article.md index 80ebf7360..05dbacc17 100644 --- a/1-js/06-advanced-functions/04-var/article.md +++ b/1-js/06-advanced-functions/04-var/article.md @@ -207,81 +207,81 @@ sayHi(); در هر دو مثال بالا، `alert` بدون هیچ اروری اجرا می‌شود چون متغیر `phrase` وجود دارد. اما مقدار آن هنوز تخصیص داده نشده است پس `undefined` را نشان می‌شود. -## IIFE +## روش IIFE -In the past, as there was only `var`, and it has no block-level visibility, programmers invented a way to emulate it. What they did was called "immediately-invoked function expressions" (abbreviated as IIFE). +در گذشته، چون فقط `var` وجود داشت و قابلیت رویت در بلوک کد را ندارد، برنامه‌نویسان برای تقلید آن راهی ایجاد کردند. کاری کردند را «فراخوانی بلافاصله‌ی function expressionها (immediately-invoked function expressions)» است (خلاصه شده به عنوان IIFE). -That's not something we should use nowadays, but you can find them in old scripts. +امروزه از این روش نباید استفاده کنیم اما می‌توانید آن‌ها را در اسکریپت‌های قدیمی پیدا کنید. -An IIFE looks like this: +یک IIFE اینگونه به نظر می‌رسد: ```js run (function() { - var message = "Hello"; + var message = "سلام"; - alert(message); // Hello + alert(message); // سلام })(); ``` -Here, a Function Expression is created and immediately called. So the code executes right away and has its own private variables. +اینجا، یک Function Expression ساخته شده و بلافاصله فراخوانی شده است. پس کد هر چه سریع‌تر اجرا می‌شود و متغیرهای مخصصوص خودش را دارد. -The Function Expression is wrapped with parenthesis `(function {...})`, because when JavaScript engine encounters `"function"` in the main code, it understands it as the start of a Function Declaration. But a Function Declaration must have a name, so this kind of code will give an error: +Function Expression درون پرانتز قرار گرفته است `(function {...})` چون زمانی که موتور جاوااسکریپت در کد اصلی با `"function"` مواجه می‌شود، آن را به عنوان ابتدای یک Function Declaration فرض می‌کند. اما یک Function Declaration باید اسم داشته باشد پس کدی به این شکل ارور ایجاد می‌کند: ```js run -// Tries to declare and immediately call a function +// سعی می‌کنیم یک تابع را تعریف و بلافاصله فراخوانی کنیم function() { // <-- SyntaxError: Function statements require a function name - var message = "Hello"; + var message = "سلام"; - alert(message); // Hello + alert(message); // سلام }(); ``` -Even if we say: "okay, let's add a name", that won't work, as JavaScript does not allow Function Declarations to be called immediately: +حتی اگر بگوییم: «مشکلی نیست، بیایید یک اسم اضافه کنیم» باز هم کار نمی‌کند چون جاوااسکریپت اجازه نمی‌دهد که Function Declarationها بلافاصله فراخوانی شوند: ```js run -// syntax error because of parentheses below +// به دلیل وجود پرانتزهای پایین ارور سینتکس دریافت می‌کنیم function go() { -}(); // <-- can't call Function Declaration immediately +}(); // <-- را بلافاصله فراخوانی کرد Function Declaration نمی‌توان ``` -So, the parentheses around the function is a trick to show JavaScript that the function is created in the context of another expression, and hence it's a Function Expression: it needs no name and can be called immediately. +پس پرانتزهای دور تابع یک ترفند است تا به جاوااسکریپت نشان دهیم که تابع در زمینه‌ی عبارتی دیگر ساخته شده و از این رو یک Function Expression است: به اسم نیازی ندارد و می‌تواند بلافاصله فراخوانی شود. -There exist other ways besides parentheses to tell JavaScript that we mean a Function Expression: +برای اینکه به جاوااسکریپت بگوییم که منظورمان یک Function Expression است راه‌های دیگری در کنار پرانتزها وجود دارد: ```js run -// Ways to create IIFE +// IIFE راه‌هایی برای ایجاد (function() { - alert("Parentheses around the function"); + alert("پرانتزهای دور تابع"); }*!*)*/!*(); (function() { - alert("Parentheses around the whole thing"); + alert("پرانتزهای دور تمام عبارت"); }()*!*)*/!*; *!*!*/!*function() { - alert("Bitwise NOT operator starts the expression"); + alert("عملگر NOT بیتی عبارت را آغاز می‌کند"); }(); *!*+*/!*function() { - alert("Unary plus starts the expression"); + alert("عملگر مثبت یگانه عبارت را آغاز می‌کند"); }(); ``` -In all the above cases we declare a Function Expression and run it immediately. Let's note again: nowadays there's no reason to write such code. +در تمام موارد بالا ما یک Function Expression تعریف می‌کنیم و آن را بلافاصله فراخوانی می‌کنیم. بیایید دوباره به این موضوع توجه کنیم: امروزه هیج دلیلی برای نوشتن چنین کدی وجود ندارد. -## Summary +## خلاصه -There are two main differences of `var` compared to `let/const`: +بین `var` و `let/const` دو تفاوت اصلی وجود دارد: -1. `var` variables have no block scope, their visibility is scoped to current function, or global, if declared outside function. -2. `var` declarations are processed at function start (script start for globals). +1. متغیرهای `var` محدودیت بلوک ندارند، قابلیت رویت آن‌ها یا محدود به تابع کنونی است یا اگر بیرون از تابع تعریف شده باشند محدود به گلوبال است. +2. تعریف متغیر با `var` در ابتدای اجرای تابع پردازش می‌شود (یا برای متغیرهای گلوبال در ابتدای اسکریپت). -There's one more very minor difference related to the global object, that we'll cover in the next chapter. +یک تفاوت جزئی دیگر در رابطه با شیء گلوبال وجود دارد که در فصل بعدی آن را بیان می‌کنیم. -These differences make `var` worse than `let` most of the time. Block-level variables is such a great thing. That's why `let` was introduced in the standard long ago, and is now a major way (along with `const`) to declare a variable. +این تفاوت‌های در اکثر اوقات `var` را نسبت به `let` بدتر جلوه می‌دهند. متغیرهای سطح بلوک چیز خیلی خوبی هستند. به این دلیل است که خیلی قبل‌تر `let` در استاندارد معرفی شد و حالا برای تعریف متغیر روش اصلی است (در کنار `const`). From 8419d8c59261d62522ceca946ded4a77c93a9f14 Mon Sep 17 00:00:00 2001 From: MaHdi Date: Sat, 9 Oct 2021 19:11:14 +0330 Subject: [PATCH 8/9] Apply suggestions from code review Co-authored-by: Mahdyar Hasanpour --- 1-js/06-advanced-functions/04-var/article.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/1-js/06-advanced-functions/04-var/article.md b/1-js/06-advanced-functions/04-var/article.md index 05dbacc17..f8dc8defd 100644 --- a/1-js/06-advanced-functions/04-var/article.md +++ b/1-js/06-advanced-functions/04-var/article.md @@ -1,5 +1,5 @@ -# کلمه "var" قدیمی +# ‌کلمه‌ی "var" قدیمی ```smart header="این مقاله برای فهمیدن اسکریپت‌های قدیمی است" اطلاعات این مقاله برای فهمیدن اسکریپت‌های قدیمی مفید است. @@ -22,7 +22,7 @@ alert(message); // سلام اما از دورن، `var` گونه‌ای بسیار متفاوت است که از زمان‌های قدیم وجود دارد. به طور کلی در اسکریپت‌های جدید استفاده نمی‌شود ولی هنوز هم در اسکریپت‌های قدیمی کمین کرده است. -اگر شما قرار نیست چنین اسکریپت‌هایی را ببینید می‌توانید این فصل را رد کنید یا مطالعه آن را به عقب بندازید. +اگر شما قرار نیست چنین اسکریپت‌هایی را ببینید می‌توانید این فصل را رد کنید یا مطالعه آن را عقب بیاندازید. از سویی دیگر، زمانی که اسکریپت‌های قدیمی را از `var` به `let` کوچ می‌دهیم، دانستن تفاوت‎ها برای جلوگیری از ارورهای عجیب مهم است. @@ -265,7 +265,7 @@ function go() { }()*!*)*/!*; *!*!*/!*function() { - alert("عملگر NOT بیتی عبارت را آغاز می‌کند"); + alert("عملگر بیتی NOT عبارت را آغاز می‌کند"); }(); *!*+*/!*function() { From 1710d2bf2b906891b362473e3685d8aa4de5b77f Mon Sep 17 00:00:00 2001 From: MaHdi Date: Sat, 9 Oct 2021 19:13:01 +0330 Subject: [PATCH 9/9] Fix a typo and change a word --- 1-js/06-advanced-functions/04-var/article.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/1-js/06-advanced-functions/04-var/article.md b/1-js/06-advanced-functions/04-var/article.md index f8dc8defd..abb9e70d0 100644 --- a/1-js/06-advanced-functions/04-var/article.md +++ b/1-js/06-advanced-functions/04-var/article.md @@ -20,13 +20,13 @@ var message = "سلام"; alert(message); // سلام ``` -اما از دورن، `var` گونه‌ای بسیار متفاوت است که از زمان‌های قدیم وجود دارد. به طور کلی در اسکریپت‌های جدید استفاده نمی‌شود ولی هنوز هم در اسکریپت‌های قدیمی کمین کرده است. +اما از درون، `var` گونه‌ای بسیار متفاوت است که از زمان‌های قدیم وجود دارد. به طور کلی در اسکریپت‌های جدید استفاده نمی‌شود ولی هنوز هم در اسکریپت‌های قدیمی کمین کرده است. اگر شما قرار نیست چنین اسکریپت‌هایی را ببینید می‌توانید این فصل را رد کنید یا مطالعه آن را عقب بیاندازید. از سویی دیگر، زمانی که اسکریپت‌های قدیمی را از `var` به `let` کوچ می‌دهیم، دانستن تفاوت‎ها برای جلوگیری از ارورهای عجیب مهم است. -## کلمه "var" محدوده بلوک ندارد +## کلمه‌ی "var" محدوده بلوک ندارد متغیرهایی که با `var` تعریف شده‌اند، یا محدوده تابع دارند یا محدوده گلوبال. آن‌ها در این بلوک‌ها قابل رویت هستند.