Skip to content

Commit 34fd845

Browse files
authored
Merge branch 'master' into lookaround
2 parents c4c0c00 + ec5c967 commit 34fd845

File tree

362 files changed

+5496
-3074
lines changed

Some content is hidden

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

362 files changed

+5496
-3074
lines changed

Diff for: 1-js/01-getting-started/1-intro/article.md

+44-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"]

Diff for: 1-js/02-first-steps/01-hello-world/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
আমরা পুরো URL টিও দিতে পারি। উদাহরণস্বরূপ:
7979

8080
```html
81-
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.2.0/lodash.js"></script>
81+
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.js"></script>
8282
```
8383

8484
একাধিক ট্যাগ ব্যবহার করে, একাধিক স্ক্রিপ্টগুলো সংযুক্ত করতে পারিঃ

Diff for: 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

Diff for: 1-js/02-first-steps/03-strict-mode/article.md

+40
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919
...
2020
```
2121

22+
<<<<<<< HEAD
2223
শিঘ্রই আমরা ফাংশন (কমান্ড গ্রুপ করার একটি উপায়) শিখব। একটু এগিয়ে গিয়ে নোট করে নেয়া যাক, `"use strict"` কোন ফাংশনের বডির শুরুতেও দেয়া যায়। এতে করে শুধু ঐ ফাংশনে স্ট্রিক্ট মোড সক্রিয় হয়। তবে সাধারণত পুরো স্ক্রিপ্টের জন্যই স্ট্রিক্ট মোড ব্যবহার করা হয়।
2324

25+
=======
26+
Quite soon we're going to learn functions (a way to group commands), so let's note in advance that `"use strict"` can be put at the beginning of a function. Doing that enables strict mode in that function only. But usually people use it for the whole script.
27+
>>>>>>> d6e88647b42992f204f57401160ebae92b358c0d
2428
2529
````warn header="\"use strict\" সবার শুরুতে থাকতে হবে"
2630
নিশ্চিত করুন যেন `"use strict"` আপনার স্ক্রিপ্টগুলোর একেবারে সবার উপরে থাকে। নাহলে স্ট্রিক্ট মোড নাও সক্রিয় হতে পারে।
@@ -47,11 +51,21 @@ alert("some code");
4751
4852
## ব্রাউজার কনসোল
4953
54+
<<<<<<< HEAD
5055
ভবিষ্যতে আপনি যখন ব্রাউজার কনসোলে কোন ফিচার পরীক্ষা করতে যাবেন, মনে রাখবেন ডিফল্টভাবে সেটা স্ট্রিক্ট মোডে থাকে না।
56+
=======
57+
When you use a [developer console](info:devtools) to run code, please note that it doesn't `use strict` by default.
58+
>>>>>>> d6e88647b42992f204f57401160ebae92b358c0d
5159
5260
কখনো কখনো যখন `use strict`-এ পার্থক্য হয়, আপনি ভুল ফলাফল পাবেন।
5361
62+
<<<<<<< HEAD
5463
একাধিক লাইন দেয়ার জন্য `key:Shift+Enter` চেপে সবার উপরে `use strict` দিয়ে দেখতে পারেন, এভাবে:
64+
=======
65+
So, how to actually `use strict` in the console?
66+
67+
First, you can try to press `key:Shift+Enter` to input multiple lines, and put `use strict` on top, like this:
68+
>>>>>>> d6e88647b42992f204f57401160ebae92b358c0d
5569
5670
```js
5771
'use strict'; <নতুন লাইনের জন্য Shift+Enter>
@@ -61,12 +75,17 @@ alert("some code");
6175

6276
বেশিরভাগ ব্রাউজার যেমন ক্রোম, ফায়ারফক্সে এটা কাজ করে।
6377

78+
<<<<<<< HEAD
6479
যদি কাজ না করে তাহলে `use strict` নিশ্চিত করার সবচেয়ে নির্ভরযোগ্য উপায় হল কোডটাকে কনসোলে এভাবে ইনপুট দেয়া:
80+
=======
81+
If it doesn't, e.g. in an old browser, there's an ugly, but reliable way to ensure `use strict`. Put it inside this kind of wrapper:
82+
>>>>>>> d6e88647b42992f204f57401160ebae92b358c0d
6583
6684
```js
6785
(function() {
6886
'use strict';
6987

88+
<<<<<<< HEAD
7089
// ...আপনার কোড...
7190
})()
7291
```
@@ -83,3 +102,24 @@ alert("some code");
83102
২. একটি স্ক্রিপ্ট কিংবা ফাংশনের সবার উপরে `"use strict"` দিয়ে স্ট্রিক্ট মোড সক্রিয় করা যায়। ভাষার কিছু ফিচার, যেমন "classes" এবং "modules" স্বয়ংক্রিয়ভাবে স্ট্রিক্ট মোড সক্রিয় করে।
84103
৩. সব মর্ডান ব্রাউজারই স্ট্রিক্ট মোড সমর্থন করে।
85104
৪. আমরা পরামর্শ দিয়েছি সব সময় `"use strict"` দিয়ে স্ক্রিপ্ট শুরু করতে। এই টিউটোরিয়ালের সকল উদাহরণ ধরে নেয় যে স্ট্রিক্ট মোড চালু আছে, যদিনা অন্যথা (খুবই বিরল) উল্লেখ করে দেয়া থাকে।
105+
=======
106+
// ...your code here...
107+
})()
108+
```
109+
110+
## Should we "use strict"?
111+
112+
The question may sound obvious, but it's not so.
113+
114+
One could recommend to start scripts with `"use strict"`... But you know what's cool?
115+
116+
Modern JavaScript supports "classes" and "modules" - advanced language structures (we'll surely get to them), that enable `use strict` automatically. So we don't need to add the `"use strict"` directive, if we use them.
117+
118+
**So, for now `"use strict";` is a welcome guest at the top of your scripts. Later, when your code is all in classes and modules, you may omit it.**
119+
120+
As of now, we've got to know about `use strict` in general.
121+
122+
In the next chapters, as we learn language features, we'll see the differences between the strict and old modes. Luckily, there aren't many and they actually make our lives better.
123+
124+
All examples in this tutorial assume strict mode unless (very rarely) specified otherwise.
125+
>>>>>>> d6e88647b42992f204f57401160ebae92b358c0d

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

+15-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ let user = 'John'
8080

8181
Technically, all these variants do the same thing. So, it's a matter of personal taste and aesthetics.
8282

83-
8483
````smart header="`var` instead of `let`"
8584
In older scripts, you may also find another keyword: `var` instead of `let`:
8685

@@ -135,6 +134,20 @@ alert(hello); // Hello world!
135134
alert(message); // Hello world!
136135
```
137136
137+
````warn header="Declaring twice triggers an error"
138+
A variable should be declared only once.
139+
140+
A repeated declaration of the same variable is an error:
141+
142+
```js run
143+
let message = "This";
144+
145+
// repeated 'let' leads to an error
146+
let message = "That"; // SyntaxError: 'message' has already been declared
147+
```
148+
So, we should declare a variable once and then refer to it without `let`.
149+
````
150+
138151
```smart header="Functional languages"
139152
It's interesting to note that there exist [functional](https://en.wikipedia.org/wiki/Functional_programming) programming languages, like [Scala](http://www.scala-lang.org/) or [Erlang](http://www.erlang.org/) that forbid changing variable values.
140153
@@ -190,7 +203,7 @@ let имя = '...';
190203
let 我 = '...';
191204
```
192205
193-
Technically, there is no error here, such names are allowed, but there is an international tradition to use English in variable names. Even if we're writing a small script, it may have a long life ahead. People from other countries may need to read it some time.
206+
Technically, there is no error here. Such names are allowed, but there is an international convention to use English in variable names. Even if we're writing a small script, it may have a long life ahead. People from other countries may need to read it some time.
194207
````
195208

196209
````warn header="Reserved names"

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

+34-24
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
# Data types
22

3-
A variable in JavaScript can contain any data. A variable can at one moment be a string and at another be a number:
3+
A value in JavaScript is always of a certain type. For example, a string or a number.
4+
5+
There are eight basic data types in JavaScript. Here, we'll cover them in general and in the next chapters we'll talk about each of them in detail.
6+
7+
We can put any type in a variable. For example, a variable can at one moment be a string and then store a number:
48

59
```js
610
// no error
711
let message = "hello";
812
message = 123456;
913
```
1014

11-
Programming languages that allow such things are called "dynamically typed", meaning that there are data types, but variables are not bound to any of them.
12-
13-
There are eight basic data types in JavaScript. Here, we'll cover them in general and in the next chapters we'll talk about each of them in detail.
15+
Programming languages that allow such things, such as JavaScript, are called "dynamically typed", meaning that there exist data types, but variables are not bound to any of them.
1416

1517
## Number
1618

@@ -64,23 +66,28 @@ We'll see more about working with numbers in the chapter <info:number>.
6466

6567
## BigInt
6668

67-
In JavaScript, the "number" type cannot represent integer values larger than <code>2<sup>53</sup></code> (or less than <code>-2<sup>53</sup></code> for negatives), that's a technical limitation caused by their internal representation. That's about 16 decimal digits, so for most purposes the limitation isn't a problem, but sometimes we need really big numbers, e.g. for cryptography or microsecond-precision timestamps.
69+
In JavaScript, the "number" type cannot represent integer values larger than <code>(2<sup>53</sup>-1)</code> (that's `9007199254740991`), or less than <code>-(2<sup>53</sup>-1)</code> for negatives. It's a technical limitation caused by their internal representation.
70+
71+
For most purposes that's quite enough, but sometimes we need really big numbers, e.g. for cryptography or microsecond-precision timestamps.
6872

6973
`BigInt` type was recently added to the language to represent integers of arbitrary length.
7074

71-
A `BigInt` is created by appending `n` to the end of an integer literal:
75+
A `BigInt` value is created by appending `n` to the end of an integer:
7276

7377
```js
7478
// the "n" at the end means it's a BigInt
7579
const bigInt = 1234567890123456789012345678901234567890n;
7680
```
7781

78-
As `BigInt` numbers are rarely needed, we devoted them a separate chapter <info:bigint>.
82+
As `BigInt` numbers are rarely needed, we don't cover them here, but devoted them a separate chapter <info:bigint>. Read it when you need such big numbers.
83+
7984

80-
```smart header="Compatability issues"
81-
Right now `BigInt` is supported in Firefox and Chrome, but not in Safari/IE/Edge.
85+
```smart header="Compatibility issues"
86+
Right now, `BigInt` is supported in Firefox/Chrome/Edge/Safari, but not in IE.
8287
```
8388

89+
You can check [*MDN* BigInt compatibility table](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#Browser_compatibility) to know which versions of a browser are supported.
90+
8491
## String
8592

8693
A string in JavaScript must be surrounded by quotes.
@@ -123,7 +130,7 @@ We'll cover strings more thoroughly in the chapter <info:string>.
123130
```smart header="There is no *character* type."
124131
In some languages, there is a special "character" type for a single character. For example, in the C language and in Java it is called "char".
125132
126-
In JavaScript, there is no such type. There's only one type: `string`. A string may consist of only one character or many of them.
133+
In JavaScript, there is no such type. There's only one type: `string`. A string may consist of zero characters (be empty), one character or many of them.
127134
```
128135

129136
## Boolean (logical type)
@@ -163,7 +170,7 @@ In JavaScript, `null` is not a "reference to a non-existing object" or a "null p
163170

164171
It's just a special value which represents "nothing", "empty" or "value unknown".
165172

166-
The code above states that `age` is unknown or empty for some reason.
173+
The code above states that `age` is unknown.
167174

168175
## The "undefined" value
169176

@@ -174,30 +181,33 @@ The meaning of `undefined` is "value is not assigned".
174181
If a variable is declared, but not assigned, then its value is `undefined`:
175182

176183
```js run
177-
let x;
184+
let age;
178185

179-
alert(x); // shows "undefined"
186+
alert(age); // shows "undefined"
180187
```
181188

182-
Technically, it is possible to assign `undefined` to any variable:
189+
Technically, it is possible to explicitly assign `undefined` to a variable:
183190

184191
```js run
185-
let x = 123;
192+
let age = 100;
186193

187-
x = undefined;
194+
// change the value to undefined
195+
age = undefined;
188196

189-
alert(x); // "undefined"
197+
alert(age); // "undefined"
190198
```
191199

192-
...But we don't recommend doing that. Normally, we use `null` to assign an "empty" or "unknown" value to a variable, and we use `undefined` for checks like seeing if a variable has been assigned.
200+
...But we don't recommend doing that. Normally, one uses `null` to assign an "empty" or "unknown" value to a variable, while `undefined` is reserved as a default initial value for unassigned things.
193201

194202
## Objects and Symbols
195203

196204
The `object` type is special.
197205

198-
All other types are called "primitive" because their values can contain only a single thing (be it a string or a number or whatever). In contrast, objects are used to store collections of data and more complex entities. We'll deal with them later in the chapter <info:object> after we learn more about primitives.
206+
All other types are called "primitive" because their values can contain only a single thing (be it a string or a number or whatever). In contrast, objects are used to store collections of data and more complex entities.
207+
208+
Being that important, objects deserve a special treatment. We'll deal with them later in the chapter <info:object>, after we learn more about primitives.
199209

200-
The `symbol` type is used to create unique identifiers for objects. We mention it here for completeness, but we'll study it after objects.
210+
The `symbol` type is used to create unique identifiers for objects. We have to mention it here for the sake of completeness, but also postpone the details till we know objects.
201211

202212
## The typeof operator [#type-typeof]
203213

@@ -241,16 +251,16 @@ typeof alert // "function" (3)
241251
The last three lines may need additional explanation:
242252

243253
1. `Math` is a built-in object that provides mathematical operations. We will learn it in the chapter <info:number>. Here, it serves just as an example of an object.
244-
2. The result of `typeof null` is `"object"`. That's wrong. It is an officially recognized error in `typeof`, kept for compatibility. Of course, `null` is not an object. It is a special value with a separate type of its own. So, again, this is an error in the language.
245-
3. The result of `typeof alert` is `"function"`, because `alert` is a function. We'll study functions in the next chapters where we'll also see that there's no special "function" type in JavaScript. Functions belong to the object type. But `typeof` treats them differently, returning `"function"`. That's not quite correct, but very convenient in practice.
254+
2. The result of `typeof null` is `"object"`. That's an officially recognized error in `typeof` behavior, coming from the early days of JavaScript and kept for compatibility. Definitely, `null` is not an object. It is a special value with a separate type of its own.
255+
3. The result of `typeof alert` is `"function"`, because `alert` is a function. We'll study functions in the next chapters where we'll also see that there's no special "function" type in JavaScript. Functions belong to the object type. But `typeof` treats them differently, returning `"function"`. That also comes from the early days of JavaScript. Technically, such behavior isn't correct, but can be convenient in practice.
246256

247257
## Summary
248258

249259
There are 8 basic data types in JavaScript.
250260

251-
- `number` for numbers of any kind: integer or floating-point, integers are limited by ±2<sup>53</sup>.
261+
- `number` for numbers of any kind: integer or floating-point, integers are limited by <code>±(2<sup>53</sup>-1)</code>.
252262
- `bigint` is for integer numbers of arbitrary length.
253-
- `string` for strings. A string may have one or more characters, there's no separate single-character type.
263+
- `string` for strings. A string may have zero or more characters, there's no separate single-character type.
254264
- `boolean` for `true`/`false`.
255265
- `null` for unknown values -- a standalone type that has a single value `null`.
256266
- `undefined` for unassigned values -- a standalone type that has a single value `undefined`.

0 commit comments

Comments
 (0)