Skip to content

Commit 7608deb

Browse files
committed
run prettier and fix typos
1 parent 3f47b42 commit 7608deb

37 files changed

+327
-336
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
.grunt
33
/_book/
4+
.vscode

Diff for: README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
Learn Javascript
2-
======
1+
# Learn Javascript
32

43
This book will teach you the basics of programming and Javascript. Whether you are an experienced programmer or not, this book is intended for everyone who wishes to learn the JavaScript programming language.
54

65
![Screen](./assets/intro.png)
76

8-
JavaScript (*JS for short*) is the programming language that enables web pages to respond to user interaction beyond the basic level. It was created in 1995, and is today one of the most famous and used programming languages.
7+
JavaScript (_JS for short_) is the programming language that enables web pages to respond to user interaction beyond the basic level. It was created in 1995, and is today one of the most famous and used programming languages.

Diff for: SUMMARY.md

+37-38
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,39 @@
11
# Summary
22

3-
* [Basics](basics/README.md)
4-
* [Comments](basics/comments.md)
5-
* [Variables](basics/variables.md)
6-
* [Types](basics/types.md)
7-
* [Equality](basics/equality.md)
8-
* [Numbers](numbers/README.md)
9-
* [Creation](numbers/create.md)
10-
* [Basic Operators](numbers/operators.md)
11-
* [Advanced Operators](numbers/advanced.md)
12-
* [Strings](strings/README.md)
13-
* [Creation](strings/create.md)
14-
* [Concatenation](strings/concat.md)
15-
* [Length](strings/length.md)
16-
* [Conditional Logic](conditional/README.md)
17-
* [If](conditional/if.md)
18-
* [Else](conditional/else.md)
19-
* [Comparators](conditional/comparators.md)
20-
* [Concatenate](conditional/concatenate.md)
21-
* [Arrays](arrays/README.md)
22-
* [Indices](arrays/indices.md)
23-
* [Length](arrays/length.md)
24-
* [Loops](loops/README.md)
25-
* [For](loops/for.md)
26-
* [While](loops/while.md)
27-
* [Do...While](loops/dowhile.md)
28-
* [Functions](functions/README.md)
29-
* [Declare](functions/declare.md)
30-
* [Higher order](functions/higher_order.md)
31-
* [Objects](objects/README.md)
32-
* [Creation](objects/creation.md)
33-
* [Properties](objects/properties.md)
34-
* [Mutable](objects/mutable.md)
35-
* [Reference](objects/reference.md)
36-
* [Prototype](objects/prototype.md)
37-
* [Delete](objects/delete.md)
38-
* [Enumeration](objects/enumeration.md)
39-
* [Global footprint](objects/global_footprint.md)
40-
3+
- [Basics](basics/README.md)
4+
- [Comments](basics/comments.md)
5+
- [Variables](basics/variables.md)
6+
- [Types](basics/types.md)
7+
- [Equality](basics/equality.md)
8+
- [Numbers](numbers/README.md)
9+
- [Creation](numbers/create.md)
10+
- [Basic Operators](numbers/operators.md)
11+
- [Advanced Operators](numbers/advanced.md)
12+
- [Strings](strings/README.md)
13+
- [Creation](strings/create.md)
14+
- [Concatenation](strings/concat.md)
15+
- [Length](strings/length.md)
16+
- [Conditional Logic](conditional/README.md)
17+
- [If](conditional/if.md)
18+
- [Else](conditional/else.md)
19+
- [Comparators](conditional/comparators.md)
20+
- [Concatenate](conditional/concatenate.md)
21+
- [Arrays](arrays/README.md)
22+
- [Indices](arrays/indices.md)
23+
- [Length](arrays/length.md)
24+
- [Loops](loops/README.md)
25+
- [For](loops/for.md)
26+
- [While](loops/while.md)
27+
- [Do...While](loops/dowhile.md)
28+
- [Functions](functions/README.md)
29+
- [Declare](functions/declare.md)
30+
- [Higher order](functions/higher_order.md)
31+
- [Objects](objects/README.md)
32+
- [Creation](objects/creation.md)
33+
- [Properties](objects/properties.md)
34+
- [Mutable](objects/mutable.md)
35+
- [Reference](objects/reference.md)
36+
- [Prototype](objects/prototype.md)
37+
- [Delete](objects/delete.md)
38+
- [Enumeration](objects/enumeration.md)
39+
- [Global footprint](objects/global_footprint.md)

Diff for: arrays/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ Here is a simple array:
99
```javascript
1010
// 1, 1, 2, 3, 5, and 8 are the elements in this array
1111
var numbers = [1, 1, 2, 3, 5, 8];
12-
```
12+
```

Diff for: arrays/length.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Arrays have a property called length, and it's pretty much exactly as it sounds, it's the length of the array.
44

55
```javascript
6-
var array = [1 , 2, 3];
6+
var array = [1, 2, 3];
77

88
// Result: l = 3
99
var l = array.length;

Diff for: basics/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ In this first chapter, we'll learn the basics of programming and the Javascript
44

55
Programming means writing code. A book is made up of chapters, paragraphs, sentences, phrases, words and finally punctuation and letters, likewise a program can be broken down into smaller and smaller components. For now, the most important is a statement. A statement is analogous to a sentence in a book. On its own, it has structure and purpose, but without the context of the other statements around it, it isn't that meaningful.
66

7-
A statement is more casually (and commonly) known as a *line of code*. That's because statements tend to be written on individual lines. As such, programs are read from top to bottom, left to right. You might be wondering what code (also called source code) is. That happens to be a broad term which can refer to the whole of the program or the smallest part. Therefore, a line of code is simply a line of your program.
7+
A statement is more casually (and commonly) known as a _line of code_. That's because statements tend to be written on individual lines. As such, programs are read from top to bottom, left to right. You might be wondering what code (also called source code) is. That happens to be a broad term which can refer to the whole of the program or the smallest part. Therefore, a line of code is simply a line of your program.
88

99
Here is a simple example:
1010

@@ -16,4 +16,4 @@ var world = "World";
1616
var message = hello + " " + world;
1717
```
1818

19-
This code can be executed by another program called an *interpreter* that will read the code, and execute all the statements in the right order.
19+
This code can be executed by another program called an _interpreter_ that will read the code, and execute all the statements in the right order.

Diff for: basics/comments.md

+2-27
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ Comments are statements that will not be executed by the interpreter, comments a
44

55
In Javascript, comments can be written in 2 different ways:
66

7-
* Line starting with `//`:
7+
- Line starting with `//`:
88

99
```javascript
1010
// This is a comment, it will be ignored by the interpreter
1111
var a = "this is a variable defined in a statement";
1212
```
1313

14-
* Section of code starting with `/*`and ending with `*/`, this method is used for multi-line comments:
14+
- Section of code starting with `/*`and ending with `*/`, this method is used for multi-line comments:
1515

1616
```javascript
1717
/*
@@ -20,28 +20,3 @@ it will be ignored by the interpreter
2020
*/
2121
var a = "this is a variable defined in a statement";
2222
```
23-
24-
25-
---
26-
27-
Mark the editor's contents as a comment
28-
29-
```js
30-
31-
Mark me as a comment
32-
or I'll throw an error
33-
34-
```
35-
36-
```js
37-
/*
38-
Mark me as a comment
39-
or I'll throw an error
40-
*/
41-
```
42-
43-
```js
44-
assert(true);
45-
```
46-
47-
---

Diff for: basics/equality.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22

33
Programmers frequently need to determine the equality of variables in relation to other variables. This is done using an equality operator.
44

5-
The most basic equality operator is the `==` operator. This operator does everything it can to determine if two variables are equal, even if they are not of the same type.
5+
The most basic equality operator is the `==` operator. This operator does everything it can to determine if two variables are equal, even if they are not of the same type.
66

77
For example, assume:
8+
89
```javascript
910
var foo = 42;
1011
var bar = 42;
1112
var baz = "42";
1213
var qux = "life";
1314
```
1415

15-
`foo == bar` will evaluate to `true` and `baz == qux` will evaluate to `false`, as one would expect. However, `foo == baz` will *also* evaluate to `true` despite `foo` and `baz` being different types. Behind the scenes the `==` equality operator attempts to force its operands to the same type before determining their equality. This is in contrast to the `===` equality operator.
16+
`foo == bar` will evaluate to `true` and `baz == qux` will evaluate to `false`, as one would expect. However, `foo == baz` will _also_ evaluate to `true` despite `foo` and `baz` being different types. Behind the scenes the `==` equality operator attempts to force its operands to the same type before determining their equality. This is in contrast to the `===` equality operator.
1617

17-
The `===` equality operator determines that two variables are equal if they are of the same type *and* have the same value. With the same assumptions as before, this means that `foo === bar` will still evaluate to `true`, but `foo === baz` will now evaluate to `false`. `baz === qux` will still evaluate to `false`.
18+
The `===` equality operator determines that two variables are equal if they are of the same type _and_ have the same value. With the same assumptions as before, this means that `foo === bar` will still evaluate to `true`, but `foo === baz` will now evaluate to `false`. `baz === qux` will still evaluate to `false`.

Diff for: basics/types.md

+11-10
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,24 @@ Computers are sophisticated and can make use of more complex variables than just
44

55
The most common types are:
66

7-
* **Numbers**
8-
* **Float**: a number, like 1.21323, 4, -33.5, 100004 or 0.123
9-
* **Integer**: a number like 1, 12, -33, 140 but not 1.233
7+
- **Numbers**
108

11-
* **String**: a line of text like "boat", "elephant" or "damn, you are tall!"
9+
- **Float**: a number, like 1.21323, 4, -33.5, 100004 or 0.123
10+
- **Integer**: a number like 1, 12, -33, 140 but not 1.233
1211

13-
* **Boolean**: either true or false, but nothing else
12+
- **String**: a line of text like "boat", "elephant" or "damn, you are tall!"
1413

15-
* **Arrays**: a collection of values like: 1,2,3,4,'I am bored now'
14+
- **Boolean**: either true or false, but nothing else
1615

17-
* **Objects**: a representation of a more complex object
16+
- **Arrays**: a collection of values like: 1,2,3,4,'I am bored now'
1817

19-
* **null**: a variable that contains null contains no valid Number, String, Boolean, Array, or Object
18+
- **Objects**: a representation of a more complex object
2019

21-
* **undefined**: the undefined value is obtained when you use an object property that does not exist, or a variable that has been declared, but has no value assigned to it.
20+
- **null**: a variable that contains null contains no valid Number, String, Boolean, Array, or Object
2221

23-
JavaScript is a *“loosely typed”* language, which means that you don't have to explicitly declare what type of data the variables are. You just need to use the ```var``` keyword to indicate that you are declaring a variable, and the interpreter will work out what data type you are using from the context, and use of quotes.
22+
- **undefined**: the undefined value is obtained when you use an object property that does not exist, or a variable that has been declared, but has no value assigned to it.
23+
24+
JavaScript is a _“loosely typed”_ language, which means that you don't have to explicitly declare what type of data the variables are. You just need to use the `var` keyword to indicate that you are declaring a variable, and the interpreter will work out what data type you are using from the context, and use of quotes.
2425

2526
{% exercise %}
2627
Create a variable named `a` using the keyword `var`.

Diff for: conditional/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ First of all conditions can be used to ensure that your program works, regardles
66

77
The other thing conditions can do for you is allow for branching. You might have encountered branching diagrams before, for example when filling out a form. Basically, this refers to executing different “branches” (parts) of code, depending on if the condition is met or not.
88

9-
In this chapter, we'll learn the base of conditional logic in Javascript.
9+
In this chapter, we'll learn the base of conditional logic in Javascript.

Diff for: conditional/comparators.md

+9-10
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,16 @@ if (country === "France") {
88
}
99
```
1010

11-
The conditional part is the variable `country` followed by the three equal signs (`===`). Three equal signs tests if the variable `country` has both the correct value (`France`) and also the correct type (`String`). You can test conditions with double equal signs, too, however a conditional such as `if (x == 5)` would then return true for both `var x = 5;` and `var x = "5";`. Depending on what your program is doing, this could make quite a difference. It is highly recommended as a best practice that you always compare equality with three equal signs (`===` and `!==`) instead of two (`==` and `!=`).
11+
The conditional part is the variable `country` followed by the three equal signs (`===`). Three equal signs tests if the variable `country` has both the correct value (`France`) and also the correct type (`String`). You can test conditions with double equal signs, too, however a conditional such as `if (x == 5)` would then return true for both `var x = 5;` and `var x = "5";`. Depending on what your program is doing, this could make quite a difference. It is highly recommended as a best practice that you always compare equality with three equal signs (`===` and `!==`) instead of two (`==` and `!=`).
1212

1313
Other conditional test:
1414

15-
* ```x > a```: is x bigger than a?
16-
* ```x < a```: is x less than a?
17-
* ```x <= a```: is x less than or equal to a?
18-
* ```x >=a```: is x greater than or equal to a?
19-
* ```x != a```: is x not a?
20-
* ```x```: does x exist?
21-
15+
- `x > a`: is x bigger than a?
16+
- `x < a`: is x less than a?
17+
- `x <= a`: is x less than or equal to a?
18+
- `x >=a`: is x greater than or equal to a?
19+
- `x != a`: is x not a?
20+
- `x`: does x exist?
2221

2322
{% exercise %}
2423
Add a condition to change the value of `a` to the number 10 if `x` is bigger than 5.
@@ -30,7 +29,7 @@ var x = 6;
3029
var a = 0;
3130

3231
if (x > 5) {
33-
a = 10;
32+
a = 10;
3433
}
3534
{% validation %}
3635
assert(a === 10);
@@ -41,7 +40,7 @@ assert(a === 10);
4140
In order to avoid the if-else hassle, simple logical comparisons can be utilised.
4241

4342
```js
44-
var topper = (marks > 85) ? "YES" : "NO";
43+
var topper = marks > 85 ? "YES" : "NO";
4544
```
4645

4746
In the above example, `?` is a logical operator. The code says that if the value of marks is greater than 85 i.e. `marks > 85` , then `topper = YES` ; otherwise `topper = NO` . Basically, if the comparison condition proves true, the first argument is accessed and if the comparison condition is false , the second argument is accessed.

Diff for: conditional/concatenate.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ In JavaScript “or” is written as `||` and “and” is written as `&&`.
66

77
Say you want to test if the value of x is between 10 and 20—you could do that with a condition stating:
88

9-
```
10-
if(x > 10 && x < 20) {
9+
```javascript
10+
if (x > 10 && x < 20) {
1111
...
1212
}
1313
```
1414

1515
If you want to make sure that country is either “England” or “Germany” you use:
1616

17-
```
18-
if(country === 'England' || country === 'Germany') {
17+
```javascript
18+
if (country === "England" || country === "Germany") {
1919
...
2020
}
2121
```
2222

23-
**Note**: Just like operations on numbers, Condtions can be grouped using parenthesis, ex: ```if ( (name === "John" || name === "Jennifer") && country === "France")```.
23+
**Note**: Just like operations on numbers, Condtions can be grouped using parenthesis, ex: `if ( (name === "John" || name === "Jennifer") && country === "France")`.
2424

2525
{% exercise %}
2626
Fill up the 2 conditions so that `primaryCategory` equals `"E/J"` only if name equals `"John"` and country is `"England"`, and so that `secondaryCategory` equals `"E|J"` only if name equals `"John"` or country is `"England"`
@@ -29,22 +29,22 @@ var name = "John";
2929
var country = "England";
3030
var primaryCategory, secondaryCategory;
3131

32-
if ( /* Fill here */ ) {
33-
primaryCategory = "E/J";
32+
if ( /_ Fill here _/ ) {
33+
primaryCategory = "E/J";
3434
}
35-
if ( /* Fill here */ ) {
36-
secondaryCategory = "E|J";
35+
if ( /_ Fill here _/ ) {
36+
secondaryCategory = "E|J";
3737
}
3838
{% solution %}
3939
var name = "John";
4040
var country = "England";
4141
var primaryCategory, secondaryCategory;
4242

4343
if (name === "John" && country === "England") {
44-
primaryCategory = "E/J";
44+
primaryCategory = "E/J";
4545
}
4646
if (name === "John" || country === "England") {
47-
secondaryCategory = "E|J";
47+
secondaryCategory = "E|J";
4848
}
4949
{% validation %}
5050
assert(primaryCategory === "E/J" && secondaryCategory === "E|J");

Diff for: conditional/else.md

+11-12
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,25 @@ There is also an `else` clause that will be applied when the first condition isn
55
```javascript
66
var umbrellaMandatory;
77

8-
if(country === 'England'){
9-
umbrellaMandatory = true;
8+
if (country === "England") {
9+
umbrellaMandatory = true;
1010
} else {
11-
umbrellaMandatory = false;
11+
umbrellaMandatory = false;
1212
}
1313
```
1414

1515
The `else` clause can be joined with another `if`. Lets remake the example from the previous article:
1616

1717
```javascript
18-
if(country === 'England') {
19-
...
20-
} else if(country === 'France') {
21-
...
22-
} else if(country === 'Germany') {
23-
...
18+
if (country === "England") {
19+
...
20+
} else if (country === "France") {
21+
...
22+
} else if (country === "Germany") {
23+
...
2424
}
2525
```
2626

27-
2827
{% exercise %}
2928
Fill up the value of `name` to validate the `else` condition.
3029
{% initial %}
@@ -33,15 +32,15 @@ var name =
3332
if (name === "John") {
3433

3534
} else if (name === "Aaron") {
36-
// Valid this condition
35+
// Valid this condition
3736
}
3837
{% solution %}
3938
var name = "Aaron";
4039

4140
if (name === "John") {
4241

4342
} else if (name === "Aaron") {
44-
// Valid this condition
43+
// Valid this condition
4544
}
4645
{% validation %}
4746
assert(name === "Aaron");

0 commit comments

Comments
 (0)