Skip to content

Commit 8f20976

Browse files
author
Md. Jamal Uddin
authored
Merge pull request #6 from shimulch/Code-structure
Code structure
2 parents 8415785 + c19c7d4 commit 8f20976

File tree

1 file changed

+67
-67
lines changed

1 file changed

+67
-67
lines changed

Diff for: 1-js/02-first-steps/02-structure/article.md

+67-67
Original file line numberDiff line numberDiff line change
@@ -1,159 +1,159 @@
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+
যেমন, এখানে আমরা "হ্যালো ওয়ার্ল্ড" - কে দুটি আলাদা alert এ দেখাচ্ছিঃ
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 the semicolon is not required. 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

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+
আপনি যদি এধরণের এররের একটি উদাহরণ দেখতে আগ্রহী হন, তাহলে এই কোডটি দেখুনঃ
5757
5858
```js run
5959
[1, 2].forEach(alert)
6060
```
6161
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`
6363
64-
Now, let's add an `alert` before the code and *not* finish it with a semicolon:
64+
এবার, কোডের শুরুতে একটি `alert` বসাই এবং সেমিকোলন ছাড়াই লাইনটি শেষ করিঃ
6565
6666
```js run no-beautify
67-
alert("There will be an error")
67+
alert("একটি এরর তৈরি হবে")
6868
6969
[1, 2].forEach(alert)
7070
```
7171
72-
Now if we run the code, only the first `alert` is shown and then we have an error!
72+
এখন যদি আমরা কোডটি রান করি, শুধুমাত্র শুরুর `alert` টি দেখায় এবং এরপর আমরা একটি এরর পাই!
7373
74-
But everything is fine again if we add a semicolon after `alert`:
74+
কিন্তু আমরা যদি `alert` এর পর একটি সেমিকোলন দেই, তাহলে সব ঠিকঠাক কাজ করেঃ
7575
```js run
76-
alert("All fine now");
76+
alert("সবকিছু ঠিক আছে");
7777
78-
[1, 2].forEach(alert)
78+
[1, 2].forEach(alert)
7979
```
8080
81-
Now we have the "All fine now" message followed by `1` and `2`.
81+
এখন আমরা "সবকিছু ঠিক আছে" বার্তাটি এবং তার সাথে `1` `2` পাই।
8282
8383
84-
The error in the no-semicolon variant occurs because JavaScript does not assume a semicolon before square brackets `[...]`.
84+
সেমিকোলন ছাড়া কোডে এরর হয়েছে তার কারণ জাভাস্ক্রিপ্ট তৃতীয় বন্ধনীর `[...]` আগে সেমিকোলন হবে তা অনুমান করতে পারে নি।
8585
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+
সুতরাং, যেহেতু সেমিকোলন স্বয়ংক্রিয়ভাবে বসানো হয়নি, তাই প্রথম উদাহরণের কোড পুরোটাই একটি স্টেটমেন্ট হিসেবে গণ্য করা হয়েছে। জাভাস্ক্রিপ্ট ইঞ্জিন কোডটাকে এভাবে দেখছেঃ
8787
8888
```js run no-beautify
89-
alert("There will be an error")[1, 2].forEach(alert)
89+
alert("একটি এরর তৈরি হবে")[1, 2].forEach(alert)
9090
```
9191
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+
কিন্তু এখানে একটি নয়, দুটো আলাদা স্টেটমেন্ট হবে। এভাবে একটি লাইনে যোগ করে ফেলাটা পুরোপুরি ভুল, তাই এররটি তৈরি হয়েছে। এমনটা আরও অনেক পরিস্থিতিতে হতে পারে।
9393
````
9494

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+
আমরা স্টেটমেন্টের শেষে সেমিকোলন দিতে পরামর্শ দেই, এমনকি যদি স্টেটমেন্টগুলো আলাদা লাইনেও হয়ে থাকে। এই রুলটি কমিউনিটিতে ব্যাপকভাবে গ্রহণ করা হয়েছে। আরও একবার এভাবে বলা যায় -- অধিকাংশ সময় সেমিকোলন ঊহ্য রাখা **সম্ভব**। কিন্তু এটি ব্যবহার করা নিরাপদ -- বিশেষ করে শিক্ষানবিশ/অনভিজ্ঞদের জন্য।
9696

97-
## Comments
97+
## কমেন্ট/মন্তব্য
9898

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+
সময়ের সাথে সাথে প্রোগ্রামগুলো অধিক থেকে অধিকতর জটিল হতে থাকে। *কমেন্ট/মন্তব্য* লিখার মাধ্যমে কোড কি কাজ করে এবং কেন করে তা প্রয়োজনীয় হয়ে দাঁড়ায়।
100100

101-
Comments can be put into any place of a script. They don't affect its execution because the engine simply ignores them.
101+
কমেন্ট স্ক্রিপ্টের যেকোনো জায়গায় লেখা যায়। কমেন্ট কোড এক্সিকিউশনে কোন প্রভাব ফেলে না কারণ জাভাস্ক্রিপ্ট ইঞ্জিন কমেন্টগুলো উপেক্ষা করে।
102102

103-
**One-line comments start with two forward slash characters `//`.**
103+
**এক-লাইনের কমেন্টগুলো দুটি ফরওয়ার্ড স্লাশ ক্যারেক্টার `//` দিয়ে শুরু হয়।**
104104

105-
The rest of the line is a comment. It may occupy a full line of its own or follow a statement.
105+
লাইনের পরবর্তী অংশ একটি কমেন্ট। কমেন্ট নিজেই পুরো একটি লাইন নিয়ে নিতে পারে বা একটি স্টেটমেন্টের পরে বসতে পারে।
106106

107-
Like here:
107+
যেমনটা এখানেঃ
108108
```js run
109-
// This comment occupies a line of its own
110-
alert('Hello');
109+
// এই কমেন্টটি নিজেই পুরো লাইন নিয়ে নিয়েছে
110+
alert('হ্যালো');
111111

112-
alert('World'); // This comment follows the statement
112+
alert('ওয়ার্ল্ড'); // এই কমেন্টটি স্টেটমেন্টের পরে বসেছে
113113
```
114114

115-
**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>.**
115+
**একাধিক লাইনের কমেন্টগুলো একটি ফরওয়ার্ড স্লাশ ও একটি তারকাচিহ্ন <code>/&#42;</code> দিয়ে শুরু হয় এবং একটি তারকাচিহ্ন ও একটি ফরওয়ার্ড স্লাশ <code>&#42;/</code> দিয়ে শেষ হয়।**
116116

117-
Like this:
117+
যেমনটা এখানেঃ
118118

119119
```js run
120-
/* An example with two messages.
121-
This is a multiline comment.
120+
/* দুটো বার্তার একটি উদাহরণ
121+
এটি একটি একাধিক লাইনের কমেন্ট
122122
*/
123-
alert('Hello');
124-
alert('World');
123+
alert('হ্যালো');
124+
alert('ওয়ার্ল্ড');
125125
```
126126

127-
The content of comments is ignored, so if we put code inside <code>/&#42; ... &#42;/</code>, it won't execute.
127+
কমেন্টের বিষয়বস্তু উপেক্ষা করা হয়, তাই আমরা যদি <code>/&#42; ... &#42;/</code> এর ভেতরে কোড লিখি, তা কাজ করবে না।
128128

129-
Sometimes it can be handy to temporarily disable a part of code:
129+
মাঝে মাঝে কোডের কিছু অংশ সাময়িকভাবে অচল করার জন্য কমেন্ট খুব কাজে আসেঃ
130130

131131
```js run
132-
/* Commenting out the code
133-
alert('Hello');
132+
/* কোডকে কমেন্ট করা হচ্ছে
133+
alert('হ্যালো');
134134
*/
135-
alert('World');
135+
alert('ওয়ার্ল্ড');
136136
```
137137

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`.
138+
```smart header="হট-কী ব্যবহার করুন"
139+
অধিকাংশ এডিটরে, কোডের কোন অংশ কমেন্ট করতে, এক লাইনের কমেন্টের জন্য `key:Ctrl+/` হট-কী এবং একাধিক লাইনের কমেন্টের জন্য `key:Ctrl+Shift+/` হট-কী ব্যবহার করা হয় (কোডের অংশটি সিলেক্ট করে হট-কী প্রেস করা হয়)। ম্যাকের জন্য `key:Ctrl` এর পরিবর্তে `key:Cmd` ব্যবহার করে চেষ্টা করে দেখুন।
140140
```
141141

142-
````warn header="Nested comments are not supported!"
143-
There may not be `/*...*/` inside another `/*...*/`.
142+
````warn header="জাভাস্ক্রিপ্ট নেস্টেড কমেন্ট সাপোর্ট করে না!"
143+
একটি `/*...*/` এর ভেতর আরেকটি `/*...*/` থাকবে না।
144144
145-
Such code will die with an error:
145+
এধরণের কোড একটি এরর দিয়ে বন্ধ হয়ে যাবে।
146146
147147
```js run no-beautify
148148
/*
149-
/* nested comment ?!? */
149+
/* নেস্টেড কমেন্ট ?!? */
150150
*/
151-
alert( 'World' );
151+
alert('ওয়ার্ল্ড');
152152
```
153153
````
154154

155-
Please, don't hesitate to comment your code.
155+
দয়া করে কোডে কমেন্ট লিখতে দ্বিধাবোধ করবেন না।
156156

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+
যদিও কমেন্ট সম্পূর্ণ কোডকে ভারী করে, কিন্তু তা কোন সমস্যাই না। প্রোডাকশন সার্ভারে কোড পাবলিশ করার আগে কোড মিনিফাই করার জন্য অনেক টুল রয়েছে। এসব টুল কমেন্ট মুছে দেয়, তাই কমেন্টগুলো পাবলিশ করা কোডে থাকে না। সুতরাং, প্রোডাকশন এনভাইরনমেন্টে কমেন্টের কোন খারাপ প্রভাব নেই।
158158

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

Comments
 (0)