Skip to content

Commit a24736a

Browse files
committed
typos fixed
1 parent 6354dd4 commit a24736a

File tree

2 files changed

+43
-40
lines changed

2 files changed

+43
-40
lines changed

Learn/3. Control Structures (condition, loop and etc.).md

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ In this course, you will learn about:
1111

1212
|Operator|Description|Example|
1313
|:-:|:-:|:-:|
14-
|`==`|Check for value equality|`a == b`|
15-
|`!=`|Check for value inequality|`a != b`|
16-
|`===` and `!==`|Check for value **and** type (in)equality|`a === b` / `a !== b`|
17-
|`>` and `<`|Check for value being greater / smaller|`a > b` / `a < b`|
18-
|`>=` and `<=`|Check for value being greater or equal / smaller or equal|`a >= b` / `a <= b`|
19-
|`!`|Check if **note** true|`!a`|
14+
|`==`|Checks value equality|`a == b`|
15+
|`!=`|Checks value inequality|`a != b`|
16+
|`===` and `!==`|Checks value **and** type (in)equality|`a === b` / `a !== b`|
17+
|`>` and `<`|Checks value being greater / smaller|`a > b` / `a < b`|
18+
|`>=` and `<=`|Checks value being greater or equal / smaller or equal|`a >= b` / `a <= b`|
19+
|`!`|Checks if value is **not** true|`!a`|
2020

2121
One of most using statement for conditions, is `if` statement. Always keep in mind that condition in `if (condition) { .. }` simply has to be a **boolean value**.
2222

23-
Often, you'll **generate** such a boolean value with the help of `===,` `>`, `<` etc. **All these operators yield boolean values** (without changing the variables / values you're using them on).
23+
Often, you'll **generate** such a boolean value with the help of `===`, `>`, `<` and etc. **All these operators yield boolean values** (without changing the variables / values you're using them on).
2424

2525
Since `if` only wants a boolean, you of course don't have to use such an operator. If you already got a variable that holds a boolean, you can use it without any extra operator. For example:
2626

@@ -47,9 +47,9 @@ You can use the `!` operator to negate (**invert**) the value:
4747
```js
4848
const isTrue = true;
4949
if (!isTrue) {
50-
// This code will NOT execute because isTrue is true but ! inverts it (in this check)
50+
// This code will NOT execute because `isTrue` is true but `!` inverts it (in this check)
5151
} else {
52-
// This would execute because !isTrue yields false => else block executes
52+
// This would execute because `!isTrue` yields false => else block executes
5353
}
5454
```
5555

@@ -78,11 +78,11 @@ console.log('a' > 'B'); // true
7878
console.log('a' > 'b'); // false
7979
```
8080

81-
For more information of operator precedence, see this [link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence).
81+
For more information of operator precedence, see [this](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence) link.
8282

8383
## Object Conditions
8484

85-
`object`s and `array`s are special. For example:
85+
Objects and arrays are special. For example:
8686

8787
```js
8888
let obj1 = {name: "Hamid"};
@@ -108,7 +108,7 @@ console.log(obj1.name != obj2.name); // false
108108
console.log(obj1.name !== obj2.name); // false
109109
```
110110

111-
These are some reason that they are (objects) special. These also come true with `array`s. For example:
111+
These are some reason that objects are special. These also come true with arrays. For example:
112112

113113
```js
114114
let array1 = [1, 2, 3];
@@ -136,7 +136,7 @@ console.log(array1[0] !== array2[0]); // false
136136

137137
## `if` Statement
138138

139-
What is `if`? `if` is a statement. We can use `if` for create some conditions for our code. For example, we want tell `"Stop!"` when number reach `10`:
139+
What is `if`? `if` is a statement. We can use `if` for create some conditions for our code. For example, we want tell `"Stop!"` when number reaches `10`:
140140

141141
```js
142142
let number = 0;
@@ -150,7 +150,7 @@ while(true){
150150
}
151151
```
152152

153-
In above snippet, we wanted if `number` more than or equal to `10`, execution will stop. `while` is a **loop** and cover it in later... while loop is `true` (iterate for ever), number will increase by `1`. After number reach `10`, execution will stop by `if` condition.
153+
In snippet above, we wanted if `number` more than or equal to `10`, execution then stop. `while` is a **loop** and we cover it in later. while loop is `true` (iterate for ever), number then increases by `1`. After number reaches `10`, execution will stop by `if` condition.
154154

155155
We also have optional statement called `else`. If `if` condition not reach, `else` block will execute. For example:
156156

@@ -164,15 +164,15 @@ if (name === "Hamid") {
164164
}
165165
```
166166

167-
In above snippet, if `name` equal to `"Hamid"`, output will `"True!"`, else if `name` not equal to `"Hamid"`, output will `"False"`. We called this `if..else` condition (statement).
167+
In snippet above, if `name` equal to `"Hamid"`, output will be `"True!"`, else if `name` not equal to `"Hamid"`, output will be `"False"`. We called this `if..else` condition (statement).
168168

169169
## Truethy and Falsy
170170

171171
Some values are called **falsy**, like `0`, `0n`, `-0`, `null`, `undefined`, `false`, `NaN` and empty string `""`.
172172

173173
Some values are called **truthy**, like `23`, `"hi"`, `true`, `[]`, `{}`, `object = {a:1}`, `function hamid() {..}` and `[23, 24]`.
174174

175-
See below snippets:
175+
See these following snippets:
176176

177177
```js
178178
let name = "Hamid";
@@ -199,12 +199,12 @@ if (isTrue) {
199199

200200
Since if just wants a condition that returns `true` or `false`, it makes sense that you can just provide a **boolean** variable or value and it works - without the extra comparison (`if (isTrue === true`) - that would also work but is redundant).
201201

202-
Whilst the above example makes sense, it can be confusing when you encounter code like this for the first time:
202+
Whilst the example above makes sense, it can be confusing when you encounter code like this for the first time:
203203

204204
```js
205205
let userInput = 'Hamid';
206206
if (userInput) {
207-
// this code here will execute because 'Hamid' is "truthy" (all strings but empty strings are)
207+
// this code here will execute because 'Hamid' is "truthy" (all strings but empty strings are falsy)
208208
}
209209
```
210210

@@ -220,7 +220,7 @@ if (userInput) { ... }
220220

221221
## Ternary Operator
222222

223-
We can use shorthand `? :` operator for `if` statements. For example, we can write code like below:
223+
We can use shorthand `? :` operator for `if` statements. For example, we can write code like:
224224

225225
```js
226226
const name = if (isTrue) {
@@ -236,7 +236,7 @@ But with ternary operator, we can do this:
236236
const name = isTrue ? "Hamid" : null;
237237
```
238238

239-
How above snippet work? It's very simple. First, we declare a constant that called `name`. Then, we check if `isTrue` is `true`, `"Hamid"` will execute, else the condition returns `null`.
239+
How this snippet work? It's very simple. First, we declared a constant that called `name`. Then, we checked if `isTrue` is `true`, `"Hamid"` will be executed, else the condition returns `null`.
240240

241241
**Note**: `if` is statement, but **not expression**. Because it **can't** be after right-hand-side of a variable or a constant (after `=` assignment). But we can use **Ternary Operator** for this purpose. For example:
242242

@@ -270,7 +270,7 @@ We can use `||` (or) operator for variable's value. For example:
270270
let firstName = "" || "Hamid";
271271
console.log(firstName); // "Hamid"
272272

273-
let lastName = "Alavi" || "Willson"
273+
let lastName = "Alavi" || "Goertzel"
274274
console.log(lastName); // "Alavi"
275275
```
276276

@@ -292,7 +292,7 @@ And for better understanding with example, consider this table:
292292
|Value 1|Value 2|Value 3|Output|
293293
|:-:|:-:|:-:|:-:|
294294
|`false`|`false`|`true`|`true`|
295-
|`""`|`"Hamed"`|`"Ali"`|`"Ali"`|
295+
|`""`|`"Hamed"`|`"Ali"`|`"Hamed"`|
296296
|`false`|`NaN`|`"Hamid"`|`"Hamid"`|
297297
|`true`|`"Reza"`|`"Mehrdad"`|`true`|
298298

@@ -304,8 +304,8 @@ We can use `&&` (and) operator for variable's value. For example:
304304
let firstName = "" && "Hamid";
305305
console.log(firstName); // ""
306306

307-
let lastName = "Alavi" && "Willson"
308-
console.log(lastName); // "Willson"
307+
let lastName = "Alavi" && "Goertzel";
308+
console.log(lastName); // "Goertzel"
309309
```
310310

311311
In `firstName`, output is `""`, because first value is **falsy**.
@@ -338,7 +338,7 @@ And for better understanding with example, consider this table:
338338
let day = 4;
339339

340340
if (day === 1) {
341-
console.log("Monday");
341+
console.log("Monday"); // this line executed
342342
} else if (day === 2) {
343343
console.log("Tuesday");
344344
} else if (day === 3) {
@@ -356,7 +356,7 @@ if (day === 1) {
356356
}
357357
```
358358

359-
See? If we want use complex conditiion, multiple combined conditions or greater than checks and so on. We definitely want to use `if/else` blocks and statements instead of the `switch-case` statement; because that really only shines for **strict equality** checks.
359+
See? If we want touse complex condition, multiple combined conditions or greater than checks and so on, we definitely want to use `if/else` blocks and statements instead of the `switch-case` statement; because that really only shines for **strict equality** checks.
360360

361361
Let's look `switch-case` example:
362362

@@ -374,7 +374,7 @@ switch (day) {
374374
console.log("Wednesday");
375375
break;
376376
case 4:
377-
console.log("Thursday");
377+
console.log("Thursday"); // this line executed
378378
break;
379379
case 5:
380380
console.log("Friday");
@@ -392,7 +392,7 @@ switch (day) {
392392

393393
It's very easy to understand. We just pass the variable into the `()`. It means that our target is `day`. We can choose or add many conditions for that variable with `case` keyword. For example, if `day` is `4`, output will be `"Thursday"`. After each `case`, we use `break` keyword, because `break` keyword will stop rest execution after executes the matched condition.
394394

395-
**Note**: The colon (`:`) after case, is exactly like `{ .. }` for `if..else` statement .
395+
**Note**: The `:` colon after `case`, is exactly like `{ .. }` for `if..else` statement .
396396

397397
For more information, go to [this](https://stackoverflow.com/questions/32576618/switch-statement-to-compare-values-greater-or-less-than-a-number/32576647) link.
398398

@@ -433,9 +433,9 @@ for (;;) {
433433
}
434434
```
435435

436-
It looks like a infinite loop (with no conditions).
436+
It looks like a infinite loop (without conditions).
437437

438-
We also have a strage type of this loop, but we don't recommend you to this:
438+
We also have a strage type of this loop, but we don't recommend you to do this:
439439

440440
```js
441441
for (let i = 0; i < 10; i -= -1) {
@@ -526,11 +526,11 @@ See better visual output:
526526
```js
527527
let object = { name: "Hamid", age: 23 };
528528
for (let key in object) {
529-
console.log(`${key} => ${object[key]}`); // "Hamid" "23"
529+
console.log(`${key} => ${object[key]}`);
530530
}
531531
/* "name => Hamid"
532532
"age => 23"
533-
*/
533+
*/
534534
```
535535

536536
> `while` loop:
@@ -541,7 +541,7 @@ This loop executes code as long as a condition is true. For example:
541541
let i = 0;
542542
while (true) {
543543
console.log(i);
544-
i++; // --infinite loop
544+
i++; // infinite loop
545545
}
546546
```
547547

@@ -567,7 +567,7 @@ do {
567567

568568
That means: **do** something, **while** that condition is `true` (or reach).
569569

570-
**Note**: In `do..while` loops, we (you) need put semicolon (`;`) after `while` loop. Consider:
570+
**Note**: In `do..while` loops, we (you) need put `;` semicolon after `while` loop. Consider:
571571

572572
```js
573573
do {
@@ -577,7 +577,7 @@ do {
577577

578578
## `break` and `continue` Keywords
579579

580-
**JavaScript** (and other programming languages) have two important keyword.
580+
**JavaScript** (and other programming languages) have two important keywords.
581581

582582
> `break`
583583
@@ -624,7 +624,7 @@ whileLoop: do {
624624
} while (number < 10);
625625
```
626626

627-
We defined `whileLoop` label (you can choose another name for it), and we created an `if` statement (condition) to stop executing code after `number` equal to `4`. This technique rarely use in **JavaScript**.
627+
We defined `whileLoop` label (you can choose whatever you want for it), and we created an `if` statement (condition) to stop executing code after `number` equal to `4`. This technique rarely use in **JavaScript**.
628628

629629
## Nested Loops and Conditions
630630

@@ -785,7 +785,7 @@ function getMaxLifeValue() {
785785

786786
// check for invalid entered number
787787
if (isNaN(parsedValue) || parsedValue <= 0) {
788-
throw "Invalid user input, nnot a number!";
788+
throw "Invalid user input, not a number!";
789789
}
790790
return parsedValue;
791791
}
@@ -797,7 +797,7 @@ try {
797797
} catch (error) {
798798
console.log(error);
799799
maxLife = 100;
800-
alert("You enterd something wrong, deafult value of 100 was used.");
800+
alert("You entered something wrong, deafult value of 100 was used.");
801801
}
802802
```
803803

practice.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5607,5 +5607,8 @@ __proto__: WeakSet
56075607
// }
56085608
// }
56095609

5610-
const obj = {name: "hamid", age: 23, age: 25};
5611-
console.log(obj)
5610+
for (let i = 0; i < 10; i++) {
5611+
for (let j = 1; j < 10; j++) {
5612+
console.log(`i: ${i}`, `j: ${j}`);
5613+
}
5614+
}

0 commit comments

Comments
 (0)