Skip to content

Commit 0a518fe

Browse files
authored
Merge pull request #54 from javascript-tutorial/sync-c89ddc5d
Sync with upstream @ c89ddc5
2 parents 10910e1 + 116f1f8 commit 0a518fe

File tree

177 files changed

+1301
-1073
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

177 files changed

+1301
-1073
lines changed

1-js/01-getting-started/1-intro/article.md

+20-17
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<body>
5+
6+
<script>
7+
alert( "I'm JavaScript!" );
8+
</script>
9+
10+
</body>
11+
12+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
[html src="index.html"]

1-js/02-first-steps/02-structure/article.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ alert("একটি এরর তৈরি হবে")[1, 2].forEach(alert)
9494

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

97-
## কমেন্ট/মন্তব্য
97+
## কমেন্ট/মন্তব্য [#code-comments]
9898

9999
সময়ের সাথে সাথে প্রোগ্রামগুলো অধিক থেকে অধিকতর জটিল হতে থাকে। *কমেন্ট/মন্তব্য* লিখার মাধ্যমে কোড কি কাজ করে এবং কেন করে তা প্রয়োজনীয় হয়ে দাঁড়ায়।
100100

@@ -135,7 +135,7 @@ alert('হ্যালো');
135135
alert('ওয়ার্ল্ড');
136136
```
137137

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

1-js/02-first-steps/06-type-conversions/article.md

+17-28
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ alert(age); // NaN, রূপান্তর হয়নি
6363

6464
সংখ্যা রুপান্তরের নিয়ম:
6565

66-
| ভ্যালু | পরিবর্তিত রুপ... |
67-
|-------|-------------|
68-
|`undefined`|`NaN`|
69-
|`null`|`0`|
70-
|<code>true&nbsp;&nbsp;false</code> | `1``0` |
71-
| `string` | স্ট্রিংয়ের শুরু ও শেষের স্পেস থেকে তা মুছে ফেলা হয়। বাকিটা ফাঁকা স্ট্রিং হলে, তা `0` হবে। নাহয় নাম্বারগুলি স্ট্রিং থেকে নেয়া হয়। এরর হলে `NaN` আসে। |
66+
| ভ্যালু | পরিবর্তিত রুপ... |
67+
| ----------------------------------- | ---------------------------------------------------------------------------------------------------- |
68+
| `undefined` | `NaN` |
69+
| `null` | `0` |
70+
| <code>true&nbsp;&nbsp;false</code> | `1``0` |
71+
| `string` | স্ট্রিংয়ের শুরু ও শেষের স্পেস থেকে তা মুছে ফেলা হয়। বাকিটা ফাঁকা স্ট্রিং হলে, তা `0` হবে। নাহয় নাম্বারগুলি স্ট্রিং থেকে নেয়া হয়। এরর হলে `NaN` আসে। |
7272

7373
Examples:
7474

@@ -81,18 +81,7 @@ alert( Number(false) ); // 0
8181

8282
এখানে জেনে রাখি `null``undefined` এক্ষেত্রে ভিন্ন আচরণ করে: `null` হয়ে যাবে শূন্য আর `undefined` হবে `NaN`.
8383

84-
````smart header="যোগ '+' স্ট্রিংসমূহকে একীভুত করে"
85-
প্রায় সব গানিতিক অপারেটর ভ্যালুকে সংখ্যায় রূপান্তর করে নেয়। তবে উল্লেখযোগ্য একটি ব্যতিক্রম হলো যোগ `+`, যদি এর দুপাশের একটি ভ্যালুও স্ট্রিং হয় তবে অপরটিও স্ট্রিং হয়ে যাবে
86-
87-
তখন এটি স্ট্রিংগুলাকে যুক্ত করে ফেলে:
88-
89-
```js run
90-
alert( 1 + '2' ); // '12' (ডানপাশে স্ট্রিং)
91-
alert( '1' + 2 ); // '12' (বামপাশে স্ট্রিং)
92-
```
93-
94-
এটা তখনই হয় যদি অন্তত একটি আর্গুমেন্ট স্ট্রিং থাকে, নাহয় তা সংখ্যায় রুপান্তরিত হয়ে যাবে।
95-
````
84+
বেশিরভাগ গাণিতিক অপারেটর এমন পরিবর্তন করে থাকে, আমরা পরবর্তি চ্যাপ্টার এ তা দেখবো।
9685

9786
## বুলিয়ান রূপান্তর
9887

@@ -134,21 +123,21 @@ alert( Boolean(" ") ); // স্পেস, এটাও true (স্ট্রি
134123
135124
রূপান্তর নীতি:
136125
137-
| ভ্যালু | বদলে যায়... |
138-
|-------|-------------|
139-
|`undefined`|`NaN`|
140-
|`null`|`0`|
141-
|<code>true&nbsp;/&nbsp;false</code> | `1 / 0` |
142-
| `string` | স্ট্রিংয়ে যা তাই আসে, স্ট্রিংয়ের শুরু ও শেষের স্পেস থেকে তা মুছে ফেলা হয়। বাকিটা ফাঁকা স্ট্রিং হলে, তা `0` হবে। নাহয় নাম্বারগুলি স্ট্রিং থেকে নেয়া হয়। এরর হলে `NaN` আসে। |
126+
| ভ্যালু | বদলে যায়... |
127+
| ----------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
128+
| `undefined` | `NaN` |
129+
| `null` | `0` |
130+
| <code>true&nbsp;/&nbsp;false</code> | `1 / 0` |
131+
| `string` | স্ট্রিংয়ে যা তাই আসে, স্ট্রিংয়ের শুরু ও শেষের স্পেস থেকে তা মুছে ফেলা হয়। বাকিটা ফাঁকা স্ট্রিং হলে, তা `0` হবে। নাহয় নাম্বারগুলি স্ট্রিং থেকে নেয়া হয়। এরর হলে `NaN` আসে। |
143132
144133
**`বুলিয়ানে রূপান্তর`** -- লজিকাল অপারেশনে হয়। আবার `Boolean(value)` দিয়েও করা যায।
145134
146135
Follows the rules:
147136
148-
| ভ্যালু | বদলে যায়... |
149-
|-------|-------------|
150-
|`0`, `null`, `undefined`, `NaN`, `""` |`false`|
151-
|অন্য যেকোন ভ্যালু| `true` |
137+
| ভ্যালু | বদলে যায়... |
138+
| ------------------------------------- | --------- |
139+
| `0`, `null`, `undefined`, `NaN`, `""` | `false` |
140+
| অন্য যেকোন ভ্যালু | `true` |
152141
153142
154143
প্রায় সব নীতিই বুঝা অ মনে রাখা সোজা। তবে কিছু কমন ভুল হলো:

1-js/02-first-steps/07-operators/article.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,17 @@ Here's an extract from the [precedence table](https://developer.mozilla.org/en/J
138138
| Precedence | Name | Sign |
139139
|------------|------|------|
140140
| ... | ... | ... |
141-
| 16 | unary plus | `+` |
142-
| 16 | unary negation | `-` |
143-
| 14 | multiplication | `*` |
144-
| 14 | division | `/` |
141+
| 17 | unary plus | `+` |
142+
| 17 | unary negation | `-` |
143+
| 15 | multiplication | `*` |
144+
| 15 | division | `/` |
145145
| 13 | addition | `+` |
146146
| 13 | subtraction | `-` |
147147
| ... | ... | ... |
148148
| 3 | assignment | `=` |
149149
| ... | ... | ... |
150150

151-
As we can see, the "unary plus" has a priority of `16` which is higher than the `13` of "addition" (binary plus). That's why, in the expression `"+apples + +oranges"`, unary pluses work before the addition.
151+
As we can see, the "unary plus" has a priority of `17` which is higher than the `13` of "addition" (binary plus). That's why, in the expression `"+apples + +oranges"`, unary pluses work before the addition.
152152
153153
## Assignment
154154

1-js/02-first-steps/08-comparison/1-comparison-questions/solution.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ null === +"\n0\n" → false
1212

1313
কিছু কারণ:
1414

15-
1. অবশ্যই true বা ঠিক হবে।
16-
2. আভিধানিকভাবে তুলনা তাই false বা ভুল
15+
1. অবশ্যই true হবে।
16+
2. আভিধানিকভাবে তুলনা তাই false`"a"` `"p"` থেকে ছোট
1717
3. আবারও, আভিধানিকভাবে তুলনা, প্রথম স্ট্রিংয়ের `"2"` দ্বিতীয় স্ট্রিংয়ের `"1"` এর থেকে বড়।
1818
4. `null` এবং `undefined` একমাত্র একে অপরের সমান।
19-
5. যথাযথ সমতায় `===` দুটি ভ্যালু একই টাইপের হতে হয়। কিন্তু তারা ভিন্ন টাইপের
19+
5. যথাযথ সমতায় `===` দুটি ভ্যালু একই টাইপের হতে হয়। উভয় পাশের টাইপ ভিন্ন হলে false হবে
2020
6. এটি `(4)` নং এর মতো। `null` একমাত্র `undefined` এর সমান।
2121
7. দুটি ভিন্ন টাইপের ভ্যালু বা মান।

1-js/02-first-steps/11-logical-operators/2-alert-or/solution.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ alert( alert(1) || 2 || alert(3) );
66

77
alert কল করলে কোন মান রিটার্ন করে না. অথবা, এক কথায় undefined দেখায়।
88

9-
১। OR || অপারেশনে প্রথমে বাম দিক থেকে মূল্যায়ন করা হয়। সেজন্য এখানে প্রথম ফলাফল দেখায় 1
10-
২। `alert` দেখায় `undefined`, অথবা সত্য মানটির সন্ধানে দ্বিতীয় প্রতীকে যায়
11-
৩। দ্বিতীয় প্রতীক `2` সত্য হয়, সুতরাং এক্সিকিউশন স্থগিত, `2` ফিরে আসে এবং তারপরে বাইরের সতর্কতা দ্বারা দেখানো হয়।
9+
১। OR || অপারেশনে প্রথমে বাম দিক `alert(1)` মূল্যায়ন করে। সেজন্য এখানে প্রথম ফলাফল দেখায় `1`
10+
২। `alert` `undefined` রিটার্ন করে, সুতরাং OR সত্য মানের খোঁজে দ্বিতীয় অপারেন্ড এ যায়
11+
৩। দ্বিতীয় অপারেন্ড `2` সত্য হয়, সুতরাং এক্সিকিউশন স্থগিত, `2` ফিরে আসে এবং তারপরে বাইরের alert দ্বারা দেখানো হয়।
1212

1313
কোনও `3` থাকবে না, কারণ মূল্যায়ন `alert(3)` তে পৌঁছায় না।

1-js/02-first-steps/12-while-for/article.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ For even values of `i`, the `continue` directive stops executing the body and pa
256256
````smart header="The `continue` directive helps decrease nesting"
257257
A loop that shows odd values could look like this:
258258

259-
```js
259+
```js run
260260
for (let i = 0; i < 10; i++) {
261261

262262
if (i % 2) {
@@ -268,7 +268,7 @@ for (let i = 0; i < 10; i++) {
268268

269269
From a technical point of view, this is identical to the example above. Surely, we can just wrap the code in an `if` block instead of using `continue`.
270270

271-
But as a side-effect, this created one more level of nesting (the `alert` call inside the curly braces). If the code inside of`if` is longer than a few lines, that may decrease the overall readability.
271+
But as a side-effect, this created one more level of nesting (the `alert` call inside the curly braces). If the code inside of `if` is longer than a few lines, that may decrease the overall readability.
272272
````
273273
274274
````warn header="No `break/continue` to the right side of '?'"

1-js/02-first-steps/13-switch/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Several variants of `case` which share the same code can be grouped.
117117
For example, if we want the same code to run for `case 3` and `case 5`:
118118
119119
```js run no-beautify
120-
let a = 2 + 2;
120+
let a = 3;
121121
122122
switch (a) {
123123
case 4:

1-js/02-first-steps/14-function-basics/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ alert( result ); // 3
266266
267267
```js run
268268
function checkAge(age) {
269-
if (age > 18) {
269+
if (age >= 18) {
270270
*!*
271271
return true;
272272
*/!*

1-js/02-first-steps/16-arrow-functions-basics/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ let welcome = (age < 18) ?
6767
() => alert('Hello') :
6868
() => alert("Greetings!");
6969
70-
welcome(); // ok now
70+
welcome();
7171
```
7272

7373
Arrow functions may appear unfamiliar and not very readable at first, but that quickly changes as the eyes get used to the structure.

1-js/02-first-steps/17-javascript-specials/article.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ let x = 5;
8181
x = "John";
8282
```
8383

84-
There are 7 data types:
84+
There are 8 data types:
8585

8686
- `number` for both floating-point and integer numbers,
87+
- `bigint` for integer numbers of arbitrary length,
8788
- `string` for strings,
8889
- `boolean` for logical values: `true/false`,
8990
- `null` -- a type with a single value `null`, meaning "empty" or "does not exist",

1-js/03-code-quality/01-debugging-chrome/article.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Before writing more complex code, let's talk about debugging.
44

55
[Debugging](https://en.wikipedia.org/wiki/Debugging) is the process of finding and fixing errors within a script. All modern browsers and most other environments support debugging tools -- a special UI in developer tools that makes debugging much easier. It also allows to trace the code step by step to see what exactly is going on.
66

7-
We'll be using Chrome here, because it has enough features, most other browsers have a similar process`.
7+
We'll be using Chrome here, because it has enough features, most other browsers have a similar process.
88

99
## The "Sources" panel
1010

@@ -24,11 +24,11 @@ Let's click it and select `hello.js` in the tree view. Here's what should show u
2424

2525
![](chrome-tabs.svg)
2626

27-
Here we can see three zones:
27+
The Sources panel has 3 parts:
2828

29-
1. The **Resources zone** lists HTML, JavaScript, CSS and other files, including images that are attached to the page. Chrome extensions may appear here too.
30-
2. The **Source zone** shows the source code.
31-
3. The **Information and control zone** is for debugging, we'll explore it soon.
29+
1. The **File Navigator** pane lists HTML, JavaScript, CSS and other files, including images that are attached to the page. Chrome extensions may appear here too.
30+
2. The **Code Editor** pane shows the source code.
31+
3. The **JavaScript Debugging** pane is for debugging, we'll explore it soon.
3232

3333
Now you could click the same toggler <span class="devtools" style="background-position:-172px -122px"></span> again to hide the resources list and give the code some space.
3434

1-js/03-code-quality/02-coding-style/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ if (condition) {
8787
```js
8888
// ব্যাকটিক কোট ` এর সাহায্যে একটা স্ট্রিংকে ভাগ করা যায়
8989
let str = `
90-
Ecma International's TC39 is a group of JavaScript developers,
90+
ECMA International's TC39 is a group of JavaScript developers,
9191
implementers, academics, and more, collaborating with the community
9292
to maintain and evolve the definition of JavaScript.
9393
`;

1-js/03-code-quality/03-comments/article.md

+16-16
Original file line numberDiff line numberDiff line change
@@ -125,25 +125,25 @@ Describe the architecture
125125
Document function parameters and usage
126126
: There's a special syntax [JSDoc](http://en.wikipedia.org/wiki/JSDoc) to document a function: usage, parameters, returned value.
127127

128-
For instance:
129-
```js
130-
/**
131-
* Returns x raised to the n-th power.
132-
*
133-
* @param {number} x The number to raise.
134-
* @param {number} n The power, must be a natural number.
135-
* @return {number} x raised to the n-th power.
136-
*/
137-
function pow(x, n) {
138-
...
139-
}
140-
```
128+
For instance:
129+
```js
130+
/**
131+
* Returns x raised to the n-th power.
132+
*
133+
* @param {number} x The number to raise.
134+
* @param {number} n The power, must be a natural number.
135+
* @return {number} x raised to the n-th power.
136+
*/
137+
function pow(x, n) {
138+
...
139+
}
140+
```
141141

142-
Such comments allow us to understand the purpose of the function and use it the right way without looking in its code.
142+
Such comments allow us to understand the purpose of the function and use it the right way without looking in its code.
143143

144-
By the way, many editors like [WebStorm](https://www.jetbrains.com/webstorm/) can understand them as well and use them to provide autocomplete and some automatic code-checking.
144+
By the way, many editors like [WebStorm](https://www.jetbrains.com/webstorm/) can understand them as well and use them to provide autocomplete and some automatic code-checking.
145145

146-
Also, there are tools like [JSDoc 3](https://github.com/jsdoc3/jsdoc) that can generate HTML-documentation from the comments. You can read more information about JSDoc at <http://usejsdoc.org/>.
146+
Also, there are tools like [JSDoc 3](https://github.com/jsdoc3/jsdoc) that can generate HTML-documentation from the comments. You can read more information about JSDoc at <http://usejsdoc.org/>.
147147

148148
Why is the task solved this way?
149149
: What's written is important. But what's *not* written may be even more important to understand what's going on. Why is the task solved exactly this way? The code gives no answer.

1-js/03-code-quality/05-testing-mocha/article.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ We can select one of two ways to organize the test here:
159159
assert.equal(pow(2, 3), 8);
160160
});
161161
162-
it("3 raised to power 3 is 27", function() {
163-
assert.equal(pow(3, 3), 27);
162+
it("3 raised to power 4 is 81", function() {
163+
assert.equal(pow(3, 4), 81);
164164
});
165165
166166
});
@@ -182,7 +182,7 @@ The result:
182182

183183
[iframe height=250 src="pow-2" edit border="1"]
184184

185-
As we could expect, the second test failed. Sure, our function always returns `8`, while the `assert` expects `27`.
185+
As we could expect, the second test failed. Sure, our function always returns `8`, while the `assert` expects `81`.
186186

187187
## Improving the implementation
188188

1-js/03-code-quality/05-testing-mocha/pow-2.view/test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ describe("pow", function() {
44
assert.equal(pow(2, 3), 8);
55
});
66

7-
it("3 raised to power 3 is 27", function() {
8-
assert.equal(pow(3, 3), 27);
7+
it("3 raised to power 4 is 81", function() {
8+
assert.equal(pow(3, 4), 81);
99
});
1010

1111
});

0 commit comments

Comments
 (0)