|
1 |
| -# Code structure |
| 1 | +# कोड संरचना |
2 | 2 |
|
3 |
| -The first thing we'll study is the building blocks of code. |
| 3 | +पहली चीज जो हम अध्ययन करेंगे, वह है कोड की नींव की ईंटें (building blocks)। |
4 | 4 |
|
5 |
| -## Statements |
| 5 | +## उक्ति (Statements) [#उक्ति] |
6 | 6 |
|
7 |
| -Statements are syntax constructs and commands that perform actions. |
| 7 | +उक्ति कार्य करने वाले वाक्य रचना और आदेश हैं। |
8 | 8 |
|
9 |
| -We've already seen a statement, `alert('Hello, world!')`, which shows the message "Hello, world!". |
| 9 | +हमने पहले ही एक उक्ति देखा है, `alert('हेलो विश्व!')`, "हेलो विश्व" जो संदेश दिखाता है। |
10 | 10 |
|
11 |
| -We can have as many statements in our code as we want. Statements can be separated with a semicolon. |
| 11 | +हम अपने कोड में जितने चाहें उतने उक्ति दे सकते हैं। उक्ति अर्धविराम से अलग किए जा सकते हैं। |
12 | 12 |
|
13 |
| -For example, here we split "Hello World" into two alerts: |
| 13 | +उदाहरण के लिए, यहां हमने "हेलो विश्व!" को दो अलर्ट में विभाजित किया है: |
14 | 14 |
|
15 | 15 | ```js run no-beautify
|
16 |
| -alert('Hello'); alert('World'); |
| 16 | +alert('हेलो!'); alert('विश्व'); |
17 | 17 | ```
|
18 | 18 |
|
19 |
| -Usually, statements are written on separate lines to make the code more readable: |
| 19 | +आमतौर पर कोड को अधिक पठनीय बनाने के लिए अलग-अलग लाइनों पर उक्ति लिखे जाते हैं: |
20 | 20 |
|
21 | 21 | ```js run no-beautify
|
22 |
| -alert('Hello'); |
23 |
| -alert('World'); |
| 22 | +alert('हेलो'); |
| 23 | +alert('विश्व'); |
24 | 24 | ```
|
25 | 25 |
|
26 |
| -## Semicolons [#semicolon] |
| 26 | +## अर्धविराम [#अर्धविराम] |
27 | 27 |
|
28 |
| -A semicolon may be omitted in most cases when a line break exists. |
| 28 | +लाइन ब्रेक मौजूद होने पर अधिकांश मामलों में अर्धविराम छोड़ा जा सकता है। |
29 | 29 |
|
30 |
| -This would also work: |
| 30 | +यह कोड काम करेगा: |
31 | 31 |
|
32 | 32 | ```js run no-beautify
|
33 |
| -alert('Hello') |
34 |
| -alert('World') |
| 33 | +alert('हेलो') |
| 34 | +alert('विश्व') |
35 | 35 | ```
|
36 | 36 |
|
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 | +यहाँ, जावास्क्रिप्ट लाइन ब्रेक (एक पंक्ति का अंत) को "निहित" अर्धविराम के रूप में मानता है। इसे [automatic semicolon insertion](https://tc39.github.io/ecma262/#sec-automatic-semicolon-insertion) कहा जाता है। |
38 | 38 |
|
39 |
| -**In most cases, a newline implies a semicolon. But "in most cases" does not mean "always"!** |
| 39 | +**ज्यादातर मामलों में, एक नई पंक्ति का अर्थ अर्धविराम है। लेकिन "ज्यादातर मामलों में" का अर्थ "हमेशा" नहीं होता है!** |
40 | 40 |
|
41 |
| -There are cases when a newline does not mean a semicolon. For example: |
| 41 | +ऐसे मामले हैं जब एक नई लाइन का अर्थ अर्धविराम नहीं है। उदाहरण के लिए: |
42 | 42 |
|
43 | 43 | ```js run no-beautify
|
44 | 44 | alert(3 +
|
45 | 45 | 1
|
46 | 46 | + 2);
|
47 | 47 | ```
|
48 | 48 |
|
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 the semicolon is not required. And in this case that works as intended. |
| 49 | +कोड `6` आउटपुट करता है क्योंकि जावास्क्रिप्ट यहाँ अर्धविराम नहीं डालता है। यह सहज रूप से स्पष्ट है कि यदि उक्ति एक प्लस `" + "` के साथ समाप्त होता है, तो यह एक "अपूर्ण उक्ति" है, इसलिए अर्धविराम की आवश्यकता नहीं है। और इस मामले में जो इरादा के अनुसार काम करता है। |
50 | 50 |
|
51 |
| -**But there are situations where JavaScript "fails" to assume a semicolon where it is really needed.** |
| 51 | +**लेकिन ऐसी परिस्थितियां भी हैं जहां जावास्क्रिप्ट अर्धविराम लगाने के लिए "विफल" होता है, जहां इसकी वास्तव में आवश्यकता होती है।** |
52 | 52 |
|
53 |
| -Errors which occur in such cases are quite hard to find and fix. |
| 53 | +ऐसे मामलों में होने वाली त्रुटियां खोजने और ठीक करने में काफी कठिन हैं। |
54 | 54 |
|
55 |
| -````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: |
| 55 | +````smart header="एक त्रुटि का उदाहरण" |
| 56 | +यदि आप ऐसी त्रुटि का ठोस उदाहरण देखने के लिए उत्सुक हैं, तो इस कोड को देखें: |
57 | 57 |
|
58 | 58 | ```js run
|
59 | 59 | [1, 2].forEach(alert)
|
60 | 60 | ```
|
61 | 61 |
|
62 |
| -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 the code: it shows `1` then `2`. |
| 62 | +`[]` और 'forEach` के अर्थ के बारे में सोचने की आवश्यकता नहीं है। हम उनका अध्ययन बाद में करेंगे। अभी के लिए, बस कोड का परिणाम याद रखें: यह `1` दिखाता है फिर` 2`। |
63 | 63 |
|
64 |
| -Now, let's add an `alert` before the code and *not* finish it with a semicolon: |
| 64 | +अब, कोड से पहले एक `अलर्ट` जोड़ें और अर्धविराम के साथ इसे *समाप्त न करें*: |
65 | 65 |
|
66 | 66 | ```js run no-beautify
|
67 |
| -alert("There will be an error") |
| 67 | +alert("इस कोड में एक त्रुटि होगी") |
68 | 68 |
|
69 | 69 | [1, 2].forEach(alert)
|
70 | 70 | ```
|
71 | 71 |
|
72 |
| -Now if we run the code, only the first `alert` is shown and then we have an error! |
| 72 | +अब यदि हम कोड चलाते हैं, तो केवल पहले `alert` दिखाया जाता है और फिर एक त्रुटि होती है! |
73 | 73 |
|
74 |
| -But everything is fine again if we add a semicolon after `alert`: |
| 74 | +लेकिन सब कुछ फिर से ठीक है अगर हम `alert` के बाद एक अर्धविराम जोड़ते हैं: |
75 | 75 | ```js run
|
76 |
| -alert("All fine now"); |
| 76 | +alert("अब सब ठीक है"); |
77 | 77 |
|
78 | 78 | [1, 2].forEach(alert)
|
79 | 79 | ```
|
80 | 80 |
|
81 |
| -Now we have the "All fine now" message followed by `1` and `2`. |
| 81 | +अब हमें "अब सब ठीक है" संदेश मिलता है और उसके बाद `1` और` 2` मिलते हैं। |
82 | 82 |
|
83 | 83 |
|
84 |
| -The error in the no-semicolon variant occurs because JavaScript does not assume a semicolon before square brackets `[...]`. |
| 84 | +बिना अर्धविराम के संस्करण में त्रुटि होती है क्योंकि `[...]` से पहले जावास्क्रिप्ट अर्धविराम नहीं मानता है। |
85 | 85 |
|
86 |
| -So, because the semicolon is not auto-inserted, the code in the first example is treated as a single statement. Here's how the engine sees it: |
| 86 | +इसलिए, क्योंकि अर्धविराम को ऑटो-सम्मिलित नहीं किया गया है, पहले उदाहरण में कोड को एकल उक्ति माना जाता है। यहां बताया गया है कि इंजन इसे कैसे देखता है: |
87 | 87 |
|
88 | 88 | ```js run no-beautify
|
89 |
| -alert("There will be an error")[1, 2].forEach(alert) |
| 89 | +alert("इस कोड में एक त्रुटि होग")[1, 2].forEach(alert) |
90 | 90 | ```
|
91 | 91 |
|
92 |
| -But it should be two separate statements, not one. Such a merging in this case is just wrong, hence the error. This can happen in other situations. |
| 92 | +लेकिन यह दो अलग-अलग कथन होने चाहिए, एक नहीं। इस मामले में ऐसा विलय सिर्फ गलत है, इसलिए त्रुटि होती है। यह अन्य स्थितियों में हो सकता है। |
93 | 93 | ````
|
94 | 94 |
|
95 |
| -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. |
| 95 | +हम बयानों के बीच अर्धविराम लगाने की सलाह देते हैं, भले ही वे नई लाइनों से अलग हों। इस नियम को समुदाय द्वारा व्यापक रूप से अपनाया जाता है। आइए एक बार फिर ध्यान दें -- *यह संभव है* अधिकांश समय अर्धविरामों को छोड़ने के लिए। लेकिन यह सुरक्षित है -- विशेष रूप से नौसिखिए के लिए -- अर्धविराम का उपयोग करने के लिए। |
96 | 96 |
|
97 |
| -## Comments [#code-comments] |
| 97 | +## टिप्पणियाँ [#टिप्पणियाँ] |
98 | 98 |
|
99 |
| -As time goes on, programs become more and more complex. It becomes necessary to add *comments* which describe what the code does and why. |
| 99 | +जैसे-जैसे समय बीतता है, कोड अधिक से अधिक जटिल होते जाते हैं। यह आवश्यक है कि *टिप्पणियों* को जोड़ा जाए जो यह बताता है कि कोड क्या करता है और क्यों। |
100 | 100 |
|
101 |
| -Comments can be put into any place of a script. They don't affect its execution because the engine simply ignores them. |
| 101 | +टिप्पणियाँ किसी स्क्रिप्ट के किसी भी स्थान पर डाली जा सकती हैं। वे इसके निष्पादन को प्रभावित नहीं करते हैं क्योंकि इंजन उन्हें अनदेखा करता है। |
102 | 102 |
|
103 |
| -**One-line comments start with two forward slash characters `//`.** |
| 103 | +**एक-पंक्ति टिप्पणियाँ दो फ़ॉरवर्ड स्लैश वर्णों से शुरू होती हैं `//`.** |
104 | 104 |
|
105 |
| -The rest of the line is a comment. It may occupy a full line of its own or follow a statement. |
| 105 | +शेष पंक्ति एक टिप्पणी है। यह अपनी खुद की एक पूरी लाइन पर कब्जा कर सकता है या एक उक्ति के पीछे आ सकता है. |
106 | 106 |
|
107 |
| -Like here: |
| 107 | +जैसे यहाँ: |
108 | 108 | ```js run
|
109 |
| -// This comment occupies a line of its own |
110 |
| -alert('Hello'); |
| 109 | +// यह टिप्पणी स्वयं की एक लाइन पर है |
| 110 | +alert('हैलो'); |
111 | 111 |
|
112 |
| -alert('World'); // This comment follows the statement |
| 112 | +alert('विश्व'); // यह टिप्पणी उक्ति के बाद आई है |
113 | 113 | ```
|
114 | 114 |
|
115 |
| -**Multiline comments start with a forward slash and an asterisk <code>/*</code> and end with an asterisk and a forward slash <code>*/</code>.** |
| 115 | +**बहुस्तरीय टिप्पणियां आगे की स्लैश और तारांकन के साथ शुरू होती हैं <code>/*</code> और एक तारांकन और एक आगे की स्लैश के साथ समाप्त होती हैं <code>*/</code>.** |
116 | 116 |
|
117 |
| -Like this: |
| 117 | +जैसे यहाँ: |
118 | 118 |
|
119 | 119 | ```js run
|
120 |
| -/* An example with two messages. |
121 |
| -This is a multiline comment. |
| 120 | +/* दो संदेशों के साथ एक उदाहरण। |
| 121 | +यह एक बहुस्तरीय टिप्पणी है। |
122 | 122 | */
|
123 |
| -alert('Hello'); |
124 |
| -alert('World'); |
| 123 | +alert('हैलो'); |
| 124 | +alert('विश्व'); |
125 | 125 | ```
|
126 | 126 |
|
127 |
| -The content of comments is ignored, so if we put code inside <code>/* ... */</code>, it won't execute. |
| 127 | +टिप्पणियों में कोड को अनदेखा किया जाता है, इसलिए यदि हम कोड को अंदर रखते हैं, <code>/* ... */</code>, यह निष्पादित नहीं होगा। |
128 | 128 |
|
129 |
| -Sometimes it can be handy to temporarily disable a part of code: |
| 129 | +कभी-कभी इस तकनीक का उपयोग करके कोड के एक भाग को अस्थायी रूप से अक्षम करना आसान होता है |
130 | 130 |
|
131 | 131 | ```js run
|
132 |
| -/* Commenting out the code |
133 |
| -alert('Hello'); |
| 132 | +/* कोड टिप्पणी की गई है |
| 133 | +alert('हैलो'); |
134 | 134 | */
|
135 |
| -alert('World'); |
| 135 | +alert('विश्व'); |
136 | 136 | ```
|
137 | 137 |
|
138 |
| -```smart header="Use hotkeys!" |
139 |
| -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`. |
| 138 | +```smart header="हॉट कुंजी का उपयोग करें!" |
| 139 | +अधिकांश संपादकों में, कोड की एक पंक्ति को एक-लाइन टिप्पणी के लिए `key: Ctrl + /` को दबाकर टिप्पणी की जा सकती है और बहुस्तरीय टिप्पणियों के लिए `key: Ctrl + Shift + /` (कोड का एक टुकड़ा चुनें और हॉटकी दबाएं)। Mac के लिए, `key: Ctrl` के बजाय `key: Cmd` और `key: Shift` के बजाय `key: Option` आज़माएं। |
140 | 140 | ```
|
141 | 141 |
|
142 |
| -````warn header="Nested comments are not supported!" |
143 |
| -There may not be `/*...*/` inside another `/*...*/`. |
| 142 | +````warn header="टिप्पणियाँ जो अन्य टिप्पणियों के अंदर हैं समर्थित नहीं हैं!" |
| 143 | +एक `/*...*/` के अंदर `/*...*/` नहीं हो सकता है |
144 | 144 |
|
145 |
| -Such code will die with an error: |
| 145 | +इस तरह के कोड में त्रुटि होगी: |
146 | 146 |
|
147 | 147 | ```js run no-beautify
|
148 | 148 | /*
|
149 |
| - /* nested comment ?!? */ |
| 149 | + /* नेस्टेड टिप्पणी ?!? */ |
150 | 150 | */
|
151 |
| -alert( 'World' ); |
| 151 | +alert( 'विश्व' ); |
152 | 152 | ```
|
153 | 153 | ````
|
154 | 154 |
|
155 |
| -Please, don't hesitate to comment your code. |
| 155 | +कृपया, अपने कोड में टिप्पणी करने में संकोच न करें। |
156 | 156 |
|
157 |
| -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. |
| 157 | +टिप्पणियाँ कोड के समग्र आकार को बढ़ाती हैं, लेकिन यह बिल्कुल समस्या नहीं है। कई उपकरण हैं जो सर्वर पर प्रकाशित होने से पहले कोड को छोटा करते हैं। वे टिप्पणियों को हटा देते हैं, इसलिए वे काम करने वाली स्क्रिप्ट में दिखाई नहीं देते हैं। इसलिए, टिप्पणियों का अंतिम उत्पादन (production) पर नकारात्मक प्रभाव नहीं पड़ता है। |
158 | 158 |
|
159 |
| -Later in the tutorial there will be a chapter <info:code-quality> that also explains how to write better comments. |
| 159 | +बाद में ट्यूटोरियल में एक अध्याय होगा <info:code-quality> जो यह भी बताता है कि बेहतर टिप्पणी कैसे लिखनी है। |
0 commit comments