Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
163 commits
Select commit Hold shift + click to select a range
b96642d
Add semicolon
shreenanda-8 Mar 15, 2021
51b2bec
Add semicolon
shreenanda-8 Mar 15, 2021
cf6be94
fix typo
seamissu Mar 17, 2021
065e31d
improve readability of article in chapter 8, async
hirehamir Mar 16, 2021
74935be
link to deprecated v0
joaquinelio Mar 19, 2021
027b831
No polyfill needed any longer
joaquinelio Mar 19, 2021
cd4de4b
typo
joaquinelio Mar 23, 2021
081d7b2
typo
joaquinelio Mar 23, 2021
d464ee9
typo
joaquinelio Mar 23, 2021
a010fbc
typo
joaquinelio Mar 23, 2021
3855301
2 typos
LLyaudet Mar 24, 2021
8bc74f1
1 typo in 06-function-object
LLyaudet Mar 24, 2021
c2cbc4c
avoid race condition in 06-advanced-functions/09-call-apply-decorator…
LLyaudet Mar 24, 2021
33f8b4c
selection improvements
iliakan Mar 25, 2021
3264c4b
typo
joaquinelio Mar 25, 2021
f5583eb
Merge pull request #2520 from shreenanda-8/master
iliakan Mar 26, 2021
797c658
Merge pull request #2548 from joaquinelio/patch-10
iliakan Mar 26, 2021
532b64f
closes #2547
iliakan Mar 26, 2021
3b3f7c7
Merge pull request #2545 from LLyaudet/patch-6
iliakan Mar 26, 2021
0dc1961
Merge pull request #2542 from LLyaudet/patch-4
iliakan Mar 26, 2021
5f875ab
Merge pull request #2541 from LLyaudet/patch-3
iliakan Mar 26, 2021
677fb62
Merge pull request #2540 from joaquinelio/patch-9
iliakan Mar 26, 2021
ebfef9f
Merge pull request #2539 from joaquinelio/patch-8
iliakan Mar 26, 2021
0ec6e0c
Merge pull request #2538 from joaquinelio/patch-7
iliakan Mar 26, 2021
211e130
Merge pull request #2537 from joaquinelio/patch-6
iliakan Mar 26, 2021
d3f5a59
closes #2536
iliakan Mar 26, 2021
4dcd950
Merge pull request #2533 from joaquinelio/patch-5
iliakan Mar 26, 2021
8e0d226
Merge pull request #2532 from joaquinelio/patch-4
iliakan Mar 26, 2021
b8346a5
Merge pull request #2530 from hamirmahal/infra/update-article-in-asyn…
iliakan Mar 26, 2021
d4feed3
Merge pull request #2527 from seamissu/patch-5
iliakan Mar 26, 2021
b2bff50
closes #2525
iliakan Mar 26, 2021
7b76185
closes #2524
iliakan Mar 26, 2021
a4ba2bb
close #2534 by slightly changing 7-microtask-queue
hirehamir Mar 26, 2021
a662e1c
typo
joaquinelio Mar 27, 2021
67230aa
code
joaquinelio Mar 28, 2021
32eb2f9
typo
joaquinelio Mar 28, 2021
4820b97
repeated word
joaquinelio Mar 28, 2021
01ebc30
typo
joaquinelio Mar 28, 2021
c06e21f
Few grammatical corrections
VenkataPavan2494 Mar 31, 2021
6d0b314
Fix grammatical error
tamiolaf Apr 1, 2021
c722cda
Update article.md
PhilipKirner Apr 1, 2021
334d4de
pseudo function expression
lumosmind Apr 4, 2021
023ec22
typos
joaquinelio Apr 5, 2021
b896887
Fix comma splice.
m4ttsch Apr 5, 2021
a2c36c9
Fix plural typo line 414
dylan-workhub Apr 9, 2021
6de9d70
typo
joaquinelio Apr 11, 2021
dbae68c
Plunker reminder #1775
joaquinelio Apr 11, 2021
8b7bf10
store vs keeps stored
joaquinelio Apr 12, 2021
9e52cf3
Merge pull request #2578 from joaquinelio/patch-15
iliakan Apr 12, 2021
d8be8b0
Add scrollX/scrollY
iliakan Apr 15, 2021
2b33873
Merge pull request #2577 from joaquinelio/patch-14
iliakan Apr 17, 2021
3d8ab89
Merge pull request #2575 from joaquinelio/patch-13
iliakan Apr 17, 2021
35d1c85
Merge pull request #2573 from dylan-workhub/patch-1
iliakan Apr 17, 2021
adb962b
closes #2572
iliakan Apr 17, 2021
09c3914
Merge pull request #2568 from m4ttsch/patch-1
iliakan Apr 17, 2021
362e9a9
Merge pull request #2566 from joaquinelio/patch-11
iliakan Apr 17, 2021
4742c7b
Merge pull request #2565 from lumosmind/patch-8
iliakan Apr 17, 2021
8c5d3bf
Merge pull request #2562 from PhilipKirner/patch-1
iliakan Apr 17, 2021
4092b7f
Merge pull request #2561 from tamiolaf/patch-1
iliakan Apr 17, 2021
8be1642
Merge pull request #2559 from VenkataPavan2494/patch-1
iliakan Apr 17, 2021
ba0b184
Merge pull request #2558 from joaquinelio/patch-9
iliakan Apr 17, 2021
a18c710
Merge pull request #2557 from joaquinelio/patch-8
iliakan Apr 17, 2021
1b4b347
Merge pull request #2556 from joaquinelio/patch-7
iliakan Apr 17, 2021
4b10919
Merge pull request #2550 from hamirmahal/feat/update-readability-of-7…
iliakan Apr 17, 2021
e8a1cd8
Merge pull request #2552 from joaquinelio/patch-4
iliakan Apr 17, 2021
870a88c
Merge pull request #2554 from joaquinelio/patch-5
iliakan Apr 17, 2021
7d624ef
typo it's
joaquinelio Apr 18, 2021
ffd8e03
typos? easier reading - review pls
joaquinelio Apr 18, 2021
6ab384f
Merge pull request #2584 from joaquinelio/patch-7
iliakan Apr 18, 2021
47b1ca8
Fix grammar and wrong information
Violet-Bora-Lee Apr 21, 2021
0ad314c
fix grammar
Violet-Bora-Lee Apr 22, 2021
62bc619
insert empty line
Violet-Bora-Lee Apr 22, 2021
8292f9c
Update article.md
JackStaples Apr 24, 2021
07b364d
Replace preposition with verb
mikemitchell574 Apr 29, 2021
981e34b
Update article.md
joecervino Apr 30, 2021
252cccf
always strict
joaquinelio May 7, 2021
5f972c8
fix(classes): replace [[FunctionKind]] with [[IsClassConstructor]]
H2rmone May 11, 2021
243a0b1
Merge pull request #2582 from joaquinelio/patch-4
iliakan May 13, 2021
055cab1
Merge pull request #2585 from Violet-Bora-Lee/patch-1
iliakan May 13, 2021
c78b2c9
Merge pull request #2586 from Violet-Bora-Lee/patch-2
iliakan May 13, 2021
10c3bcf
Merge pull request #2588 from Violet-Bora-Lee/patch-3
iliakan May 13, 2021
4f06415
closes #2583
iliakan May 13, 2021
74d14af
minor fixes
iliakan May 13, 2021
57e7d67
Merge pull request #2592 from JackStaples/patch-2
iliakan May 13, 2021
5e9db70
Merge pull request #2593 from mikemitchell574/master
iliakan May 13, 2021
0cbf55d
Merge pull request #2595 from josecervino/patch-1
iliakan May 13, 2021
094b829
Merge pull request #2598 from joaquinelio/patch-7
iliakan May 13, 2021
339535d
Merge pull request #2599 from H2rmone/master
iliakan May 13, 2021
3bf8830
Update article.md
iliakan May 13, 2021
237920b
Update article.md
iliakan May 13, 2021
33f1b11
minor fixes
iliakan May 13, 2021
6ad8930
minor fixes
iliakan May 13, 2021
fafab82
typo
joaquinelio May 15, 2021
4177be3
Merge pull request #2602 from joaquinelio/patch-4
iliakan May 16, 2021
80956ed
closes #2600
iliakan May 16, 2021
11e0890
Fix typo.
odsantos May 16, 2021
89183a0
minor fixes
iliakan May 16, 2021
bad5236
minor fixes
iliakan May 16, 2021
70049c3
minor fixes
iliakan May 16, 2021
859fa9b
minor fixes
iliakan May 16, 2021
fb09afc
minor fixes
iliakan May 16, 2021
f598b72
minor fixes
iliakan May 16, 2021
f841402
minor fixes
iliakan May 16, 2021
18a0394
minor fixes
iliakan May 16, 2021
ac96ede
Remove mentions of :host-context
web-padawan May 17, 2021
ae8248b
minor fixes
iliakan May 17, 2021
d2ae45d
Update article.md
Dorin-David May 20, 2021
ffa79a8
minor fixes
iliakan May 24, 2021
a917f9c
minor fixes
iliakan May 24, 2021
94837c2
minor fixes
iliakan May 24, 2021
3e74537
minor fixes
iliakan May 24, 2021
006343a
minor fixes
iliakan May 24, 2021
df45aed
minor fixes
iliakan May 24, 2021
8871521
minor fixes
iliakan May 24, 2021
1770074
minor fixes
iliakan May 24, 2021
3dbe9d1
minor fixes
iliakan May 24, 2021
2fc7cb2
minor fixes
iliakan May 24, 2021
649a159
minor fixes
iliakan May 24, 2021
62db4bb
minor fixes
iliakan May 24, 2021
3288801
minor fixes
iliakan May 24, 2021
6db4961
minor fixes
iliakan May 24, 2021
4343545
minor fixes
iliakan May 24, 2021
053cc05
minor fixes
iliakan May 24, 2021
842f0e2
minor fixes
iliakan May 24, 2021
70bb265
minor fixes
iliakan May 24, 2021
fc3c071
minor fixes
iliakan May 24, 2021
7a30a00
minor fixes
iliakan May 24, 2021
6cfa8b4
minor fixes
iliakan May 24, 2021
649c758
minor fixes
iliakan May 24, 2021
f2636ee
minor fixes
iliakan May 24, 2021
9ba208f
minor fixes
iliakan May 24, 2021
cf33b67
minor fixes
iliakan May 24, 2021
f8313dc
Update article.md
AhmedElaguab May 28, 2021
88ba2c2
Merge pull request #2 from AhmedElaguab/AhmedElaguab-fix-typo
AhmedElaguab May 28, 2021
4c35f59
"not required" vs "incorrect"
joaquinelio May 29, 2021
c2d5f8e
easier to read
joaquinelio Jun 4, 2021
52cb884
Update article.md
leviding Jun 7, 2021
6a742c4
Update article.md
leviding Jun 8, 2021
581802d
minor fixes
iliakan Jun 9, 2021
68172cc
typo
joaquinelio Jun 10, 2021
0e49461
typpo
joaquinelio Jun 10, 2021
964ba15
function parameters vs arguments
iliakan Jun 13, 2021
1ccd673
Merge pull request #2624 from joaquinelio/patch-11
iliakan Jun 13, 2021
54ff266
Merge pull request #2623 from joaquinelio/patch-9
iliakan Jun 13, 2021
2b1600e
Merge pull request #2622 from leviding/patch-37
iliakan Jun 13, 2021
581117f
Merge pull request #2621 from leviding/patch-36
iliakan Jun 13, 2021
dcf4b5b
closes #2619
iliakan Jun 13, 2021
2290bd6
Merge pull request #2616 from joaquinelio/patch-8
iliakan Jun 13, 2021
bcb47b7
Merge pull request #2612 from joaquinelio/patch-4
iliakan Jun 13, 2021
5f927bd
Merge pull request #2611 from AhmedElaguab/master
iliakan Jun 13, 2021
4d46f12
Merge pull request #2606 from Dorin-David/patch-1
iliakan Jun 13, 2021
e4ac603
Merge pull request #2605 from web-padawan/patch-1
iliakan Jun 13, 2021
ee5853d
Merge pull request #2604 from odsantos/regex-methods
iliakan Jun 13, 2021
bcf2e48
minor fixes
iliakan Jun 13, 2021
225a36f
Merge branch 'master' of github.com:javascript-tutorial/en.javascript…
iliakan Jun 13, 2021
617dfc7
minor fixes
iliakan Jun 13, 2021
e2d1823
minor fixes
iliakan Jun 13, 2021
614e29e
minor fixes
iliakan Jun 13, 2021
a171b0a
fix typo in 1-js/05-data-types/03-string
ZYinMD Jun 13, 2021
e527c61
Merge pull request #2630 from ZYinMD/patch-10
iliakan Jun 13, 2021
b258e8f
minor fixes
iliakan Jun 14, 2021
fb4fc33
minor fixes
iliakan Jun 15, 2021
af29425
merging all conflicts
iliakan Jun 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions 1-js/01-getting-started/1-intro/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@

من الجيد تذكر المصطلحات الواردة أعلاه لأنها مستخدمة في مقالات المطورين على الإنترنت. سنستخدمهم أيضًا. على سبيل المثال ، إذا كانت "الميزة إكس مدعومة بواسطة في8" ، فمن المحتمل أنها تعمل في كروم و أوبرا.

<<<<<<< HEAD
```smart header="كيف تعمل المحركات؟"
=======
- [V8](https://en.wikipedia.org/wiki/V8_(JavaScript_engine)) -- in Chrome and Opera.
- [SpiderMonkey](https://en.wikipedia.org/wiki/SpiderMonkey) -- in Firefox.
- ...There are other codenames like "Chakra" for IE, "JavaScriptCore", "Nitro" and "SquirrelFish" for Safari, etc.
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c

المحركات معقدة. ولكن الأساسيات بسيطه .

Expand Down
4 changes: 4 additions & 0 deletions 1-js/01-getting-started/4-devtools/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

يفضل معظم المطورون العمل على متصفِّحي Chrome أو FireFox لاحتوائهما على أفضل أدوات المطوّر. توفر المتصفِّحات الأخرى أيضًا مجموعة أدوات للمطوّر والتي من الممكن أن تحتوي على مزايا خاصة. لكن عادةً ما تحاول اللحاق بمتصفِّحي Chrome و FireFox الأفضل من هذه الناحية. يفضل المطوّرون بشكل عام العمل على متصفِّح واحد وينتقلون إلى متصفِّح آخر عندما تكون المشكلة التي يعملون عليها محدَّدة بهذا المتصفِّح.

<<<<<<< HEAD
بناءً على ذلك، نجد أنَّ أدوات المطور مهمة للغاية لما تمتلكه من مزايا تساعدك أثناء مسيرتك في تطوير الويب عبر JavaScript. سنتعلم في البداية طريقة فتحها، واستخدامها لاستكشاف الأخطاء، وتشغيل تعليمات JavaScript ضمنها.
=======
Developer tools are potent; they have many features. To start, we'll learn how to open them, look at errors, and run JavaScript commands.
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c

أدوات المطور قوية, لديها العديد من الميزات. للبدء, سنتعلم كيفية فتحها ، والنظر في الأخطاء ، وتشغيل أوامر جافا سكريبت.

Expand Down
56 changes: 56 additions & 0 deletions 1-js/02-first-steps/02-structure/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ alert(3+
قريبًا خلال الشيفرات التي ستكتبها).
إذا كنت ترغب في الاطلاع على مثال واقعي عن هذه الحالة، إليك الشيفرة البرمجية التالية:

<<<<<<< HEAD
```
[1, 2].foreach(alert)
```
Expand All @@ -55,10 +56,36 @@ alert(3+
```
alert("There will be an error")
[1 ,2].forEach(alert)
=======
The code outputs `6` because JavaScript does not insert semicolons here. It is intuitively obvious that if the line ends with a plus `"+"`, then it is an "incomplete expression", so a semicolon there would be incorrect. And in this case, that works as intended.

**But there are situations where JavaScript "fails" to assume a semicolon where it is really needed.**

Errors which occur in such cases are quite hard to find and fix.

````smart header="An example of an error"
If you're curious to see a concrete example of such an error, check this code out:

```js run
alert("Hello");

[1, 2].forEach(alert);
```

No need to think about the meaning of the brackets `[]` and `forEach` yet. We'll study them later. For now, just remember the result of running the code: it shows `Hello`, then `1`, then `2`.

Now let's remove the semicolon after the `alert`:

```js run no-beautify
alert("Hello")

[1, 2].forEach(alert);
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
```
عند تنفيذ الشيفرة البرمجية آنذاك، سيتم إظهار التنبيه الأول فقط ثم سنحصل على خطأ. تعود الشيفرة البرمجية للعمل بشكل
صحيح مرة أخرى عند إضافة الفاصلة المنقوطة بعد التنبيه الأول:

<<<<<<< HEAD
```
alert("All fine now");
[1 ,2].forEach(alert)
Expand All @@ -72,6 +99,18 @@ alert("All fine now");

```
alert("There will be an error")[1, 2].forEach(alert)
=======
The difference compared to the code above is only one character: the semicolon at the end of the first line is gone.

If we run this code, only the first `Hello` shows (and there's an error, you may need to open the console to see it). There are no numbers any more.

That's because JavaScript does not assume a semicolon before square brackets `[...]`. So, the code in the last example is treated as a single statement.

Here's how the engine sees it:

```js run no-beautify
alert("Hello")[1, 2].forEach(alert);
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
```
ولكنهما عبارتين برمجيتين منفصلتين وليستا عبارة واحدة، وبالتالي عملية الدمج في هذه الحالة خطأ. من الممكن أن تتكرر
هذه الحالة ضمن شروط أخرى.
Expand All @@ -87,7 +126,24 @@ alert("There will be an error")[1, 2].forEach(alert)
المائلين على نفس السطر تعليقًا. ومن الممكن أن يشغل التعليق سطرًا كاملًا أو يأتي التعليق بعد العبارة البرمجية.
إليك المثال التالي الذي يشرح ما سبق:

<<<<<<< HEAD
```
=======
Looks weird, right? Such merging in this case is just wrong. We need to put a semicolon after `alert` for the code to work correctly.

This can happen in other situations also.
````

We recommend putting semicolons between statements even if they are separated by newlines. This rule is widely adopted by the community. Let's note once again -- *it is possible* to leave out semicolons most of the time. But it's safer -- especially for a beginner -- to use them.

## Comments [#code-comments]

As time goes on, programs become more and more complex. It becomes necessary to add *comments* which describe what the code does and why.

Comments can be put into any place of a script. They don't affect its execution because the engine simply ignores them.

**One-line comments start with two forward slash characters `//`.**
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c

// يمتد هذا التعليق على كامل السطر فقط

Expand Down
2 changes: 1 addition & 1 deletion 1-js/02-first-steps/05-types/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ n = 12.345;

سنرى المزيد من التعامل مع الأرقام خلال هذا الفصل <info:number>.

## BigInt
## BigInt [#bigint-type]

في جافا سكريبت، النوع "number" لا يمثل الأعداد الصحيحة أكبر من <code>(2<sup>53</sup>-1)</code> (و هو `9007199254740991`)، أو أقل من <code>-(-2<sup>53</sup>-1)</code> للأرقام السالبة. إنها قيود فنية ناتجة عن تمثيلهم الداخلي.

Expand Down
18 changes: 15 additions & 3 deletions 1-js/02-first-steps/08-operators/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,30 @@ alert( 8 % 3 ); // 2, a remainder of 8 divided by 3

### الضرب الأسي **

<<<<<<< HEAD
عامل الضرب الأسي `a ** b` يقوم بضرب الرقم `a` في نفسه عدد `b` من المرات
=======
The exponentiation operator `a ** b` raises `a` to the power of `b`.

In school maths, we write that as a<sup>b</sup>.
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c

على سبيل المثال:

```js run
alert( 2 ** 2 ); // 4 (2 multiplied by itself 2 times)
alert( 2 ** 3 ); // 8 (2 * 2 * 2, 3 times)
alert( 2 ** 4 ); // 16 (2 * 2 * 2 * 2, 4 times)
alert( 2 ** 2 ); // 2² = 4
alert( 2 ** 3 ); // 2³ = 8
alert( 2 ** 4 ); // 2⁴ = 16
```

<<<<<<< HEAD
من الناحية الرياضياتية الضرب الأسي يستخدم أيضا مع الأرقام غير الصحيحة. على سبيل المثال الجذر التربيعي هو ضرب أسي بقيمة
`1/2`:
=======
Just like in maths, the exponentiation operator is defined for non-integer numbers as well.

For example, a square root is an exponentiation by ½:
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c

```js run
alert( 4 ** (1/2) ); // 2 (power of 1/2 is the same as a square root)
Expand Down
15 changes: 15 additions & 0 deletions 1-js/02-first-steps/13-while-for/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,24 @@ break label; // تنتقل إلى الحقل بالأسفل (لا تعمل)
label: for (...)
```

<<<<<<< HEAD
إستخدام `continue` يكون ممكنًا فقط من داخل الحلقه.

`break` ربما يمكن وضعه قبل الشيفرة ايضًا, as `label: { ... }`, لكنها لا تستخدم أبدًا بهذه الطريقة. وهي تعمل أيضًا من الداخل إلى الخارج فقط.
=======
A `break` directive must be inside a code block. Technically, any labelled code block will do, e.g.:
```js
label: {
// ...
break label; // works
// ...
}
```

...Although, 99.9% of the time `break` used is inside loops, as we've seen in the examples above.

A `continue` is only possible from inside a loop.
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
````

## ملخص
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ function checkAge(age) {
}
```

<<<<<<< HEAD
لاحظ أن الأقواس حول `age > 18` غير مطلوبة ولكن تم وضعها لزيادة القدرة على قراءة الكود.
=======
Note that the parentheses around `age > 18` are not required here. They exist for better readability.
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
81 changes: 74 additions & 7 deletions 1-js/02-first-steps/15-function-basics/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ function showMessage() {
}
```

<<<<<<< HEAD
كلمة `function` تكتب أولا ثم يكتب _اسم الدالة_ ثم قائمة _parameters_ بين القوسين (يفصل بينهم بفاصلة وهي فارغة في المثال السابق) وأخيرا الكود الذي ينفذ ويسمى "the function body" بين القوسين المعقوفين.
=======
The `function` keyword goes first, then goes the *name of the function*, then a list of *parameters* between the parentheses (comma-separated, empty in the example above, we'll see examples later) and finally the code of the function, also named "the function body", between curly braces.
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c

```js
function name(parameters) {
function name(parameter1, parameter2, ... parameterN) {
...body...
}
```
Expand Down Expand Up @@ -137,25 +141,30 @@ alert( userName ); // *!*John*/!*, لم يتغير, الدالة لن تصل ل

## Parameters

<<<<<<< HEAD
يمكننا تمرير أي قيم إلى الدالة باستخدام parameters (أيضًا تسمى _function arguments_) .
=======
We can pass arbitrary data to functions using parameters.
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c

في هذا المثال الدالة لديها معاملين: `from` و `text`.

```js run
function showMessage(*!*from, text*/!*) { // arguments: from, text
function showMessage(*!*from, text*/!*) { // parameters: from, text
alert(from + ': ' + text);
}

*!*
showMessage('Ann', 'Hello!'); // Ann: Hello! (*)
showMessage('Ann', "What's up?"); // Ann: What's up? (**)
*/!*
*!*showMessage('Ann', 'Hello!');*/!* // Ann: Hello! (*)
*!*showMessage('Ann', "What's up?");*/!* // Ann: What's up? (**)
```

عند استدعاء الدالة في السطر `(*)` و `(**)` فإن القيم الممررة تنسخ إلى المتغيرات المحلية `from` و `text`. ثم تقوم الدالة باستخدامهم.

<<<<<<< HEAD
هنا مثال آخر حيث لدينا المتغير `from` وقمنا بتمريره إلى الدالة. لاحظ أن الدالة قامت بتغيير قيمة `from` ولكن التغيير لا يؤثر في المتغير الممرر لأن الدالة تحصل على نسخة من القيمة:

=======
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
```js run
function showMessage(from, text) {

Expand All @@ -174,19 +183,43 @@ showMessage(from, "Hello"); // *Ann*: Hello
alert( from ); // Ann
```

<<<<<<< HEAD
## القيم الإفتراضية

إذا لم يتم تمرير قيمة Parameter يأخذ القيمة `undefined`.
=======
When a value is passed as a function parameter, it's also called an *argument*.

In other words, to put these terms straight:

- A parameter is the variable listed inside the parentheses in the function declaration (it's a declaration time term)
- An argument is the value that is passed to the function when it is called (it's a call time term).

We declare functions listing their parameters, then call them passing arguments.

In the example above, one might say: "the function `sayMessage` is declared with two parameters, then called with two arguments: `from` and `"Hello"`".


## Default values

If a function is called, but an argument is not provided, then the corresponding value becomes `undefined`.
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c

على سبيل المثال الفنكشن السابقة `showMessage(from, text)` يمكن استدعائها وتمرير قيمة واحدة فقط:

```js
showMessage("Ann");
```

<<<<<<< HEAD
هذا ليس خطأ ولكن سينتج `"Ann: undefined"`. لم يتم تمرير `text` لذلك يتم افتراض أن `text === undefined`.

إذا أردت تخصيص قيمة إفتراضية ل `text` يمكن وضعها بعد `=`:
=======
That's not an error. Such a call would output `"*Ann*: undefined"`. As the value for `text` isn't passed, it becomes `undefined`.

We can specify the so-called "default" (to use if omitted) value for a parameter in the function declaration, using `=`:
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c

```js run
function showMessage(from, *!*text = "no text given"*/!*) {
Expand All @@ -210,19 +243,33 @@ function showMessage(from, text = anotherFunction()) {
```smart header="تنفيذ القيم الإفتراضية"
في جافا سكريبت يتم تنفيذ القيم الإفتراضية في كل مرة يتم استدعاء الدالة دون تمرير قيمة.

<<<<<<< HEAD
في المثال السابق سيتم تنفيذ `anotherFunction()` في كل مرة يتم استدعا `showMessage()` دون تمرير قيمة `text`.
=======
In the example above, `anotherFunction()` isn't called at all, if the `text` parameter is provided.

On the other hand, it's independently called every time when `text` is missing.
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
```

### بديل القيم الإفتراضية

<<<<<<< HEAD
أحيانا نريدتحديد قيمة لإفتراضية ولكن ليس في تعريف الدالة بل في وقت لاحق أثناء التنفيذ.

لمعرفة المتغير الذي لم يمرر قيمته يمكننا مقارنته مع `undefined`:
=======
Sometimes it makes sense to assign default values for parameters not in the function declaration, but at a later stage.

We can check if the parameter is passed during the function execution, by comparing it with `undefined`:
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c

```js run
function showMessage(text) {
// ...

*!*
if (text === undefined) {
if (text === undefined) { // if the parameter is missing
text = 'empty message';
}
*/!*
Expand All @@ -233,22 +280,38 @@ function showMessage(text) {
showMessage(); // empty message
```

<<<<<<< HEAD
...أو نستخدم العامل `||`:

```js
// إذا لم يتم تمرير قيمة text أو تم تمرير "" يجعل قيمته 'empty'
=======
...Or we could use the `??` operator:

```js
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
function showMessage(text) {
// if text is undefined or otherwise falsy, set it to 'empty'
text = text || 'empty';
...
}
```

<<<<<<< HEAD
محركات جافا سكريبت الحديثة تدعم [nullish coalescing operator](info:nullish-coalescing-operator) `??`وهوأفضل في التعامل مع falsy values مثل `0`:

```js run
// إذا لم يوجد قيمة "count" يعرض "unknown"
function showCount(count) {
alert(count ?? "unknown");
=======
Modern JavaScript engines support the [nullish coalescing operator](info:nullish-coalescing-operator) `??`, it's better when most falsy values, such as `0`, should be considered "normal":

```js run
function showCount(count) {
// if count is undefined or null, show "unknown"
alert(count ?? "unknown");
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
}

showCount(0); // 0
Expand Down Expand Up @@ -413,7 +476,11 @@ checkPermission(..) // checks a permission, returns true/false

على سبيل المثال مكتبة [jQuery](http://jquery.com) تعرف دالة اسمها `$`. ومكتبة [Lodash](http://lodash.com/) لديها دالة اسمها `_`.

<<<<<<< HEAD
هذه مجرد استثناءات ففي العموم يجب أن يكون اسم الدالة معبرًا.
=======
These are exceptions. Generally function names should be concise and descriptive.
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
```

## الدوال == تعليقات
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
```js run
function ask(question, yes, no) {
if (confirm(question)) yes()
if (confirm(question)) yes();
else no();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@

```js run
function ask(question, yes, no) {
<<<<<<< HEAD
if (confirm(question)) yes();
else no();
=======
if (confirm(question)) yes();
else no();
>>>>>>> fb4fc33a2234445808100ddc9f5e4dcec8b3d24c
}

ask(
Expand Down
Loading