Skip to content

Commit e76dce9

Browse files
authored
Merge pull request #11 from rojcode/master
Update article.md
2 parents c2f7c0d + 463ff91 commit e76dce9

File tree

1 file changed

+48
-47
lines changed

1 file changed

+48
-47
lines changed
Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,114 @@
1-
# Code structure
1+
# پێکهاتەی کۆد
22

3-
The first thing we'll study is the building blocks of code.
3+
یەکەم شت کە لێی دەکۆڵینەوە، بنەماکانی بنیاتنانی کۆدە.
44

5-
## Statements
5+
## ستەیمێنت
66

7-
Statements are syntax constructs and commands that perform actions.
7+
بەیاننامەکان بریتین لە پێکهاتە و فەرمانەکان کە کردارەکان ئەنجام دەدەن.
88

9-
We've already seen a statement, `alert('Hello, world!')`, which shows the message "Hello, world!".
9+
پێشتر دەستەواژەی `alert('سڵاو,جیهان!')`مان بینیوە کە پەیامی "سڵاو، جیهان!" نیشان دەدات.
1010

11-
We can have as many statements in our code as we want. Statements can be separated with a semicolon.
11+
دەتوانین چەند فەرمانمان هەبێت لە کۆدەکانماندا. دەربڕینەکان دەتوانرێت بە سێمیکالۆن جیا بکرێتەوە.
1212

13-
For example, here we split "Hello World" into two alerts:
13+
بۆ نموونە لێرەدا "سڵاو جیهان" دابەش دەکەین بۆ دوو ئاگادارکردنەوە:
1414

1515
```js run no-beautify
16-
alert('Hello'); alert('World');
16+
alert('سڵام'); alert('جەهان');
1717
```
1818

19-
Usually, statements are written on separate lines to make the code more readable:
19+
دەربڕینەکان بەزۆری لەسەر دێڕی جیاواز دەنووسرێن بۆ ئەوەی کۆدەکە باشتر بخوێنرێتەوە:
2020

2121
```js run no-beautify
22-
alert('Hello');
23-
alert('World');
22+
alert('سڵام');
23+
alert('جیهان');
2424
```
2525

26-
## Semicolons [#semicolon]
26+
## نیمچە کۆلۆن [#semicolon]
2727

28-
A semicolon may be omitted in most cases when a line break exists.
28+
کاتێک هێڵ شکاندن هەبێت، ڕەنگە لە زۆربەی حاڵەتەکاندا نیمچە کۆلۆنەکە نەهێڵرێت.
2929

30-
This would also work:
30+
ئەمەش کاردەکات:
3131

3232
```js run no-beautify
33-
alert('Hello')
34-
alert('World')
33+
alert('سڵاو')
34+
alert('جیهان')
3535
```
3636

37-
Here, JavaScript interprets the line break as an "implicit" semicolon. This is called an [automatic semicolon insertion](https://tc39.github.io/ecma262/#sec-automatic-semicolon-insertion).
37+
لێرەدا جاڤاسکڕێپت دێڕشکێنەکە وەک نیمچە کۆلۆنێکی `ناڕاستەوخۆ` لێکدەداتەوە. ئەمەش پێی دەوترێت [خزاندنی نیمچە کۆلۆنی ئۆتۆماتیکی](https://tc39.github.io/ecma262/#sec-automatic-semicolon-insertion).
3838

39-
**In most cases, a newline implies a semicolon. But "in most cases" does not mean "always"!**
39+
**لە زۆربەی حاڵەتەکاندا هێڵی نوێ بە واتای نیمچە کۆلۆن دێت. بەڵام "لە زۆربەی حاڵەتەکاندا" بە مانای "هەمیشە" نایەت!**
4040

41-
There are cases when a newline does not mean a semicolon. For example:
41+
حاڵەت هەیە کە هێڵی نوێ بە مانای نیمچە کۆلۆن نییە. بۆ نموونە:
4242

4343
```js run no-beautify
4444
alert(3 +
4545
1
4646
+ 2);
4747
```
4848

49-
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.
49+
کۆدەکە `6` دەردەچێت چونکە جاڤاسکڕێپت لێرەدا نیمچە کۆلۆن ناخاتە ناوەوە.لە ڕووی ئینتێستیڤەوە ڕوونە کە ئەگەر هێڵەکە بە نیشانەی پڵەس `"+"` کۆتایی پێبێت، ئەوە دەربڕینێکی ناتەواوە، بۆیە نیمچە کۆلۆنەکەی ئەوێ هەڵەیە. وە لەم حاڵەتەدا، وەکو مەبەستی خۆی کاردەکات.
5050

51-
**But there are situations where JavaScript "fails" to assume a semicolon where it is really needed.**
51+
**بەڵام دۆخێک هەیە کە جاڤاسکڕێپت ناتوانێت گریمانە بکات کە نیمچە کۆلۆنێک بێت لەو شوێنانەی کە لە ڕاستیدا پێویستی پێیەتی.**
5252

53-
Errors which occur in such cases are quite hard to find and fix.
53+
دۆزینەوە و چاککردنی ئەو هەڵانەی کە لەم جۆرە حاڵەتانەدا ڕوودەدەن زۆر ئەستەمە.
5454

5555
````smart header="An example of an error"
56-
If you're curious to see a concrete example of such an error, check this code out:
56+
ئەگەر کنجکاویت بۆ بینینی نموونەیەکی هەڵەیەکی لەو جۆرە، ئەم کۆدە ببینە:
5757
5858
```js run
5959
alert("Hello");
6060
6161
[1, 2].forEach(alert);
6262
```
6363
64-
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`.
64+
هێشتا پێویست ناکات بیر لە مانای کەوانەکانی `"[]"` و `"forEach"` بکەینەوە. دواتر لێیان دەکۆڵینەوە. بۆ ئێستا تەنها ئەنجامی جێبەجێکردنی کۆدەکە لەبیرت بێت: `"Hello"`، پاشان `"1"`، پاشان `"2"` پیشان دەدات.
6565
66-
Now let's remove the semicolon after the `alert`:
66+
ئێستا با نیمچە کۆلۆنەکە لە دوای "ئاگادارکردنەوە" لاببەین:
6767
6868
```js run no-beautify
6969
alert("Hello")
7070
7171
[1, 2].forEach(alert);
7272
```
7373
74-
The difference compared to the code above is only one character: the semicolon at the end of the first line is gone.
74+
جیاوازی بەراورد بەو کۆدەی سەرەوە تەنها یەک پیتە: نیمچە کۆلۆنەکە لە کۆتایی دێڕی یەکەمدا نەماوە.
7575
76-
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.
76+
ئەگەر ئەم کۆدە جێبەجێ بکەین تەنها یەکەم `"Hello"` پیشان دەدرێت (و هەڵەیەک هەیە، لەوانەیە پێویستت بە کردنەوەی کۆنسۆڵەکە بێت بۆ بینینی). ئیتر ژمارە نەماوە.
7777
78-
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.
78+
ئەمەش لەبەر ئەوەیە کە جاڤاسکڕێپت چاوەڕوانی نیمچە کۆلۆن ناکات پێش کەوانە "[...]". بۆیە کۆدەکانی کۆتا نموونە وەک یەک فرمان مامەڵەی لەگەڵ دەکرێت.
7979
80-
Here's how the engine sees it:
80+
لێرەدا بزوێنەرەکەی چۆنە:
8181
8282
```js run no-beautify
8383
alert("Hello")[1, 2].forEach(alert);
8484
```
8585
86-
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.
86+
سەیرە، ڕاستە؟ یەکگرتنێکی لەو شێوەیە لەم حاڵەتەدا تەنها هەڵەیە. بۆ ئەوەی کۆدەکە بە دروستی کار بکات، پێویستە دوای `"alert"` نیمچە کۆلۆن دابنێین.
8787
88-
This can happen in other situations also.
88+
ئەمەش دەتوانێت لە بارودۆخی دیکەشدا ڕووبدات.
8989
````
9090

91-
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.
91+
پێشنیار دەکەین نیوە کۆلۆن لە نێوان فرمانەکاندا دابنێیت تەنانەت ئەگەر بە هێڵی نوێ جیا بکرێنەوە. ئەم یاسایە بە شێوەیەکی بەرفراوان لەلایەن کۆمەڵگاوە قبوڵکراوە. با دووبارە تێبینی بکەین -- *دەکرێ* زۆربەی کات نیمچە کۆلۆنەکە نەهێڵرێت. بەڵام سەلامەتترن بۆ بەکارهێنان - بە تایبەت بۆ کەسانی سەرەتایی.
9292

93-
## Comments [#code-comments]
93+
## کۆمێنتەکان [#code-comments]
9494

95-
As time goes on, programs become more and more complex. It becomes necessary to add *comments* which describe what the code does and why.
95+
بە تێپەڕبوونی کات بەرنامەکان ئاڵۆزتر دەبن. زیادکردنی *کۆمێنت* کە ڕوونی بکاتەوە کە کۆدەکە چی دەکات و بۆچی زۆر گرنگە.
9696

97-
Comments can be put into any place of a script. They don't affect its execution because the engine simply ignores them.
97+
دەتوانرێت کۆمێنتەکان لە هەر شوێنێکی سکریپتێکدا دابنرێت. کاریگەرییان لەسەر جێبەجێکردنی نییە چونکە بزوێنەرەکە تەنها پشتگوێیان دەخات.
9898

99-
**One-line comments start with two forward slash characters `//`.**
99+
**کۆمێنتەکانی یەک دێڕ بە دوو کاراکتەری ئێسلەش دەست پێدەکات`//`.**
100100

101-
The rest of the line is a comment. It may occupy a full line of its own or follow a statement.
101+
باقی دێڕەکە بۆچوونێکە. لەوانەیە دێڕێکی تەواو داگیر بکات یان دوای لێدوانێک بێت.
102102

103-
Like here:
103+
وەک لێرە:
104104
```js run
105105
// This comment occupies a line of its own
106106
alert('Hello');
107107

108108
alert('World'); // This comment follows the statement
109109
```
110110

111-
**Multiline comments start with a forward slash and an asterisk <code>/&#42;</code> and end with an asterisk and a forward slash <code>&#42;/</code>.**
111+
**سەرنجە فرە هێڵەکان بە هێڵی پێشەوە یا ئێسلەش و ئەستێرە <code>/&#42;</code> دەست پێدەکات و بە ئەستێرە و هێڵی پێشەوە <code>&#42;/</code> کۆتایی دێت.**
112112

113113
Like this:
114114

@@ -120,9 +120,9 @@ alert('Hello');
120120
alert('World');
121121
```
122122

123-
The content of comments is ignored, so if we put code inside <code>/&#42; ... &#42;/</code>, it won't execute.
123+
ناوەڕۆکی کۆمێنت پشتگوێ دەخرێت، بۆیە ئەگەر کۆدەکە بخەیتە ناو <code>/&#42; ... &#42;/</code>، کارناکات.
124124

125-
Sometimes it can be handy to temporarily disable a part of code:
125+
هەندێک جار دەتوانێت بەسوود بێت بەشێک لە کۆدەکە بۆ ماوەیەکی کاتی لەکاربخەیت:
126126

127127
```js run
128128
/* Commenting out the code
@@ -132,13 +132,14 @@ alert('World');
132132
```
133133

134134
```smart header="Use hotkeys!"
135-
In most editors, a line of code can be commented out by pressing the `key:Ctrl+/` hotkey for a single-line comment and something like `key:Ctrl+Shift+/` -- for multiline comments (select a piece of code and press the hotkey). For Mac, try `key:Cmd` instead of `key:Ctrl` and `key:Option` instead of `key:Shift`.
135+
لە زۆربەی دەستکاریکەرەکاندا دەتوانرێت دێڕێکی کۆد بکرێتەوە بە فشاردان لەسەر کلیلی گەرمی "key:Ctrl+/" بۆ کۆمێنتێکی تاکە دێڕ و شتێکی وەک "key:Ctrl+Shift+/" - بۆ سەرنجە فرە دێڕییەکان (پارچە کۆدێک هەڵبژێرە ).
136+
بۆ ماک لەبری "key:Ctrl" "key:Cmd" و لەبری "key:Shift" "key:Option" تاقی بکەرەوە.
136137
```
137138

138139
````warn header="Nested comments are not supported!"
139-
There may not be `/*...*/` inside another `/*...*/`.
140+
"/*...*/" لەوانەیە لە "/*...*/" ی تردا بوونی نەبێت.
140141
141-
Such code will die with an error:
142+
ئەم جۆرە کۆدە بە هەڵەیەک شکست دەهێنێت:
142143
143144
```js run no-beautify
144145
/*
@@ -148,8 +149,8 @@ alert( 'World' );
148149
```
149150
````
150151

151-
Please, don't hesitate to comment your code.
152+
تکایە دوودڵ مەبن لە کۆمێنتی کۆدەکانتان.
152153

153-
Comments increase the overall code footprint, but that's not a problem at all. There are many tools which minify code before publishing to a production server. They remove comments, so they don't appear in the working scripts. Therefore, comments do not have negative effects on production at all.
154+
کۆمێنتەکان شوێنپێی گشتی کۆدەکە زیاد دەکەن، بەڵام ئەوە بە هیچ شێوەیەک کێشە نییە. زۆر ئامراز هەیە کە کۆدەکان بچووک دەکەنەوە پێش ئەوەی بڵاوی بکەنەوە بۆ سێرڤەری بەرهەمهێنان. کۆمێنتەکان لادەبەن، بۆیە لە سکریپتە کارکەرەکاندا دەرناکەون. بۆیە کۆمێنتەکان بە هیچ شێوەیەک کاریگەری نەرێنی لەسەر بەرهەمهێنان نییە.
154155

155-
Later in the tutorial there will be a chapter <info:code-quality> that also explains how to write better comments.
156+
دواتر لە فێرکارییەکەدا بابەتی <info:code-quality> دەبێت کە هەروەها چۆنیەتی نووسینی کۆمێنتی باشتر ڕوون دەکاتەوە.

0 commit comments

Comments
 (0)