Skip to content

Commit 93583ea

Browse files
committed
splitted up REVIEW Week 2
1 parent 6b231c8 commit 93583ea

File tree

10 files changed

+205
-209
lines changed

10 files changed

+205
-209
lines changed

Week0/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ In week one we will discuss the following topics:
77

88
### Here are resources that we like you to read as a preparation for the coming lecture.
99

10-
- In you next lecture **Unmesh** will give you your first Git session, please look through the [GIT](https://github.com/HackYourFuture/Gitrepository) and read the learning goals.
10+
- In you next lecture **Unmesh** will give you your first Git session, please look through the [GIT](https://github.com/HackYourFuture/Git) repository and read the learning goals.
1111
- Please watch [Up Running with Bash Scripting](https://www.lynda.com/Bash-tutorials/Up-Running-Bash-Scripting/142989-2.html)
1212
as a recap on the cli classes you have had (1 hour and 25 min).
1313
- Please watch the first 5 chapters of the [Git essential training](https://www.lynda.com/Git-tutorials/Git-Essential-Training/100222-2.html)

Week1/REVIEW.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ This review covers:
1313

1414
Command Line Interface
1515

16-
[Read more...](../topics/CLI.md)
16+
[Read more...](../fundamentals/CLI.md)
1717

1818
>:star: Highly recommended :star: :take a look at the Command Line [repository](https://github.com/HackYourFuture/CommandLine) and especially review the preparations of the first lecture: https://github.com/HackYourFuture/CommandLine/blob/master/Lecture-1.md
1919
2020
## Variables
2121

2222
A "variable" is a place where you can store information, such as a string, or a number. A variable has a _name_ (that you choose) and a _value_. New variables in JavaScript are declared using one of three keywords: `let`, `const`, or `var`.
2323

24-
[Read more...](../topics/variables.md)
24+
[Read more...](../fundamentals/variables.md)
2525

2626
## Values
2727

2828
Values are the "things" that you assign to a variable. All values have a type. In our example above, the variable `x` is assigned a value of type `number`. JavaScript supports the following types:
2929

30-
[Read more...](../topics/values.md)
30+
[Read more...](../fundamentals/values.md)
3131

3232
## Operators
3333

@@ -37,4 +37,4 @@ Values are the "things" that you assign to a variable. All values have a type. I
3737
- `typeof` operator
3838
- Assignment operators
3939

40-
[Read more...](../topics/operators.md)
40+
[Read more...](../fundamentals/operators.md)

Week2/REVIEW.md

Lines changed: 10 additions & 201 deletions
Original file line numberDiff line numberDiff line change
@@ -12,223 +12,32 @@ This review covers:
1212
• Naming conventions
1313
```
1414

15-
### Recap Logical operators:
15+
## Recap Logical operators
1616

17-
```js
18-
0 = false
19-
1 = true
20-
```
21-
22-
#### AND `&&`
23-
24-
| `&&` |0|1|
25-
|------|-|-|
26-
|0|0|0|
27-
|1|0|1|
28-
29-
#### OR `||`
30-
31-
| `\|\|` |0|1|
32-
|------|-|-|
33-
|0|0|1|
34-
|1|1|1|
17+
* AND `&&`
18+
* OR `||`
19+
* NOT `!`
3520

36-
So you can say that false in combination with `&&` always returns true
37-
```js
38-
true && false //-> false
39-
false && true //-> false
40-
false || true //-> true
41-
true || false //-> true
42-
```
21+
[Read more...](../fundamentals/operators.md#logical-operators)
4322

44-
### Typeof
23+
## Typeof
4524

4625
`typeof` always returns the data type in a string.
4726

48-
So for example:
49-
```js
50-
let bar = 42;
51-
typeof bar //-> 'number'
52-
typeof typeof bar; //-> 'string'
53-
```
54-
55-
So the data type of what `typeof` returns is always a string, bar on the other hand is still a number.
27+
[Read more...]((../fundamentals/operators.md#typeof-operator)
5628

5729
## Objects
5830

59-
Variables that are objects also contain a list of things, but instead of them being in some specific order, they can be assigned to words, called "keys". Instead of "elements" the things that are inside objects are called "properties".
60-
61-
62-
```js
63-
let obj = {name: 'John', age: 24};
64-
```
65-
66-
This object has two properties: `name` and `age`. The "value" of the property `name` is the string `'John'`. The "value" of the property `age` is the number `24`.
67-
68-
When accessing object properties, you can use the dot-notation: `obj.name` or the bracket-notation: `obj["name"]`. Note that the latter looks a lot like the way to access array elements. However, here what's inside the bracket (called "key" for objects, instead of "index") must be a string.
69-
70-
```js
71-
console.log(obj.name); // -> 'John'
72-
console.log(obj['name']); // -> 'John'
73-
```
74-
75-
Just like with arrays, you can also use a variable to access properties, as long as these variables are strings. In this case you cannot use the dot-notation!
76-
77-
```js
78-
var ageKey = 'age';
79-
console.log(obj[ageKey]); // -> 24
80-
```
81-
82-
Remember that there is a very big difference between `obj[name]` and `obj["name"]`.
83-
84-
> Note:
85-
>
86-
> Thinking back of arrays, the length of an array can be retrieved by `arr.length`. So as mentioned before, arrays are just like other JavaScript objects. You could even write `arr['length']` to access the `length` property of the array. JavaScript will look: is what we put between brackets a number? Then it is an index and we'll look up the correct array element. If it's a string, it's a key and we will look up the corresponding property.
87-
31+
[Read more...]((../fundamentals/object.md)
8832

8933
## Functions
9034

9135
A function is a reusable piece of code. Functions are *very* important in JavaScript, to the extent that some people call JavaScript a "function-oriented" language. As mentioned above, variables can be of type function. In fact, *every function is a variable*.
9236

93-
The following two pieces of code have the exact same result:
94-
95-
```js
96-
function sum(a, b) {
97-
return a + b;
98-
}
99-
```
100-
101-
and
102-
103-
```js
104-
let sum = function (a, b) {
105-
return a + b;
106-
}
107-
```
108-
109-
> Note
110-
>
111-
> This is not entirely true, as in the second code, the function is "anonymous", i.e. it has no name. But in both cases, you can call the function like this: `sum(4, 5)`.
112-
113-
### Parameters & arguments
114-
115-
When writing `function sum(a, b)`, `a` and `b` are the "parameters" of the function. We say that this function has two parameters. (Sometimes, you'll see the word "arity": this function has "arity" 2, but that is something you don't have to use for now.)
116-
117-
Now, when *calling* function sum, e.g. `var s = sum(4, 5);`, we say that the numbers `4` and `5` are the "arguments" of the function. Arguments are "passed" to the function: "we pass `4` and `5` to the function `sum`".
118-
119-
So remember the difference between the word "parameter" and "argument". Many people confuse them, and that's not a big problem, but understanding the difference is always nice:
120-
121-
* A parameter is the name you want to give to the variable that is available inside of the function.
122-
* An argument is the actual value you want to assign to the parameters when you call the function.
123-
124-
A function that "has two parameters" is also said to "take/accept two arguments". But, sometimes you'll hear people say: "the function has two arguments" or "the function takes two parameters". While formally incorrect, you'll know what they mean.
125-
126-
### Calling a function on something
127-
128-
In JavaScript, you can call functions *on* something. By this, we mean that you use the dot to call the function. For instance, when we say "call method `trim` on string `s`", we mean:
129-
130-
```js
131-
let s = " this is a string ";
132-
s.trim(); // -> "this is a string"
133-
```
134-
135-
> Note
136-
>
137-
> Technically, this means that the string `s` will become the `this` special variable inside of the function.
138-
139-
However, there are functions that you don't call on anything:
140-
141-
```js
142-
function sum(a, b) { return a + b; }
143-
sum(4, 5); // -> 9
144-
```
145-
146-
Here, you call the function `sum` on nothing.
147-
148-
Most built-in functions in JavaScript, like math functions or logging functions, also use the dot:
149-
150-
```js
151-
Math.round(4.5);
152-
console.log("hello");
153-
Array.from([1, 2, 3]);
154-
```
155-
156-
Indeed, these functions are also called "on" `Math`, `console`, `Array`, and so on. However, in this case, their purpose is more to group them logically, so here it's not very important to use that terminology. We'd rather say: "call the function `Math.round` with `4.5` as an argument", i.e. we include it in the full name of the methods.
157-
158-
It's more when you think about which functions you can call "on" your own variables (strings, arrays, numbers, etc):
159-
160-
```js
161-
myString.trim();
162-
myArray.slice();
163-
myNumber.toString();
164-
...
165-
```
166-
37+
[Read more...]((../fundamentals/functions.md)
16738

16839
## Statements & expressions
16940

17041
Most programming languages that you'll encounter in real life are called "imperative" programming languages. JavaScript is such an imperative programming language. Imperative is another word for command-like. That is, you give the computer a bunch of commands after each other. First do this, then do that, etc.
17142

172-
These individual commands are called "statements" in imperative programming languages. You can compare them with sentences in the English language. They have a use by themselves, and do not need something else. "The man eats bread." is a full sentence, it conveys a meaning by itself. A sentence in English is always terminated by a period.
173-
174-
Similarly, a statement in JavaScript should provide a command by itself. JavaScript-statements are (almost always) terminated by a semicolon.
175-
176-
This is a complete statement:
177-
178-
```js
179-
let s = "HackYourFuture";
180-
```
181-
182-
It is a full command: declare a variable `s` and initialize it with `"HackYourFuture"`. JavaScript doesn't need any other information to know what we want. The statement is terminated with a semicolon.
183-
184-
However, this is not a complete statement:
185-
186-
```js
187-
4 + 5
188-
```
189-
190-
This equals `9`, but what is JavaScript to do with it? It doesn't provide a command. You'd need to do something with it, e.g. `var x = 4 + 5;` or `callFunction(4 + 5)`. We call these parts of statements "expressions". Expressions are not terminated by semicolons. Expressions always "evaluate into a value". In our example, the expression `4 + 5` "evaluates into `9`". If expressions cannot be evaluated into a value, they are invalid. For instance, `4 +` is not a valid expression, it is incomplete, because we need something else after the plus sign.
191-
192-
So, statements can *contain* expressions. Can expressions contain statements? No, they cannot. However, they can themselves contain expressions. Think about `4 + 5`: it contains the expressions `4` and `5`, as these both evaluate into a value: the expression `4` evaluates into the number `4`, it is a very simple expression. Similarly, `true`, `null`, `undefined` are all expressions.
193-
194-
### Examples of expressions
195-
196-
Here are some examples of expressions. Remember: expressions evaluate into a value, but do not provide a command:
197-
198-
* `sum(a, b)`
199-
* `a`
200-
* `a > 4 ? "yes" : "no"`
201-
* `a + b`
202-
* `a && b || c`
203-
* `arr.length`
204-
* `obj["name"]`
205-
* `[1, 2, 3]`
206-
* `arr[1]`
207-
* `[1]` (this is an array with one element!)
208-
* `function a() { return 4; }`
209-
210-
The last one requires a bit of explanation. If you write:
211-
212-
```js
213-
function a() { return 4; }
214-
```
215-
216-
by itself, this is a *statement* (a function declaration statement). However, if you write it as part of a statement, such as:
217-
218-
```js
219-
let b = function a() { return 4; }
220-
```
221-
222-
now it is an expression. This is an exceptional situation where something can be a statement or an expression.
223-
224-
### Examples of not-expressions
225-
226-
The following are not expressions:
227-
228-
* `var` -> this is a keyword, see below
229-
* `var x;` -> this is a statement
230-
* `+` -> this is only an operator
231-
* `if (a > 4) { return "yes"; } else { return "no"; }`
232-
233-
`if` is also a statement. However, it is quite a complex statement. It is also referred to as a "construct", just like `for`, `while`, `try`, etc.
234-
43+
[Read more...]((../fundamentals/statements_expressions.md)
File renamed without changes.

fundamentals/functions.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Functions
2+
3+
A function is a reusable piece of code. Functions are *very* important in JavaScript, to the extent that some people call JavaScript a "function-oriented" language. As mentioned above, variables can be of type function. In fact, *every function is a variable*.
4+
5+
The following two pieces of code have the exact same result:
6+
7+
```js
8+
function sum(a, b) {
9+
return a + b;
10+
}
11+
```
12+
13+
and
14+
15+
```js
16+
let sum = function (a, b) {
17+
return a + b;
18+
}
19+
```
20+
21+
> Note
22+
>
23+
> This is not entirely true, as in the second code, the function is "anonymous", i.e. it has no name. But in both cases, you can call the function like this: `sum(4, 5)`.
24+
25+
## Parameters & arguments
26+
27+
When writing `function sum(a, b)`, `a` and `b` are the "parameters" of the function. We say that this function has two parameters. (Sometimes, you'll see the word "arity": this function has "arity" 2, but that is something you don't have to use for now.)
28+
29+
Now, when *calling* function sum, e.g. `var s = sum(4, 5);`, we say that the numbers `4` and `5` are the "arguments" of the function. Arguments are "passed" to the function: "we pass `4` and `5` to the function `sum`".
30+
31+
So remember the difference between the word "parameter" and "argument". Many people confuse them, and that's not a big problem, but understanding the difference is always nice:
32+
33+
* A parameter is the name you want to give to the variable that is available inside of the function.
34+
* An argument is the actual value you want to assign to the parameters when you call the function.
35+
36+
A function that "has two parameters" is also said to "take/accept two arguments". But, sometimes you'll hear people say: "the function has two arguments" or "the function takes two parameters". While formally incorrect, you'll know what they mean.
37+
38+
## Calling a function on something
39+
40+
In JavaScript, you can call functions *on* something. By this, we mean that you use the dot to call the function. For instance, when we say "call method `trim` on string `s`", we mean:
41+
42+
```js
43+
let s = " this is a string ";
44+
s.trim(); // -> "this is a string"
45+
```
46+
47+
> Note
48+
>
49+
> Technically, this means that the string `s` will become the `this` special variable inside of the function.
50+
51+
However, there are functions that you don't call on anything:
52+
53+
```js
54+
function sum(a, b) { return a + b; }
55+
sum(4, 5); // -> 9
56+
```
57+
58+
Here, you call the function `sum` on nothing.
59+
60+
Most built-in functions in JavaScript, like math functions or logging functions, also use the dot:
61+
62+
```js
63+
Math.round(4.5);
64+
console.log("hello");
65+
Array.from([1, 2, 3]);
66+
```
67+
68+
Indeed, these functions are also called "on" `Math`, `console`, `Array`, and so on. However, in this case, their purpose is more to group them logically, so here it's not very important to use that terminology. We'd rather say: "call the function `Math.round` with `4.5` as an argument", i.e. we include it in the full name of the methods.
69+
70+
It's more when you think about which functions you can call "on" your own variables (strings, arrays, numbers, etc):
71+
72+
```js
73+
myString.trim();
74+
myArray.slice();
75+
myNumber.toString();
76+
...
77+
```
78+

fundamentals/objects.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Objects
2+
3+
Variables that are objects also contain a list of things, but instead of them being in some specific order, they can be assigned to words, called "keys". Instead of "elements" the things that are inside objects are called "properties".
4+
5+
6+
```js
7+
let obj = {name: 'John', age: 24};
8+
```
9+
10+
This object has two properties: `name` and `age`. The "value" of the property `name` is the string `'John'`. The "value" of the property `age` is the number `24`.
11+
12+
When accessing object properties, you can use the dot-notation: `obj.name` or the bracket-notation: `obj["name"]`. Note that the latter looks a lot like the way to access array elements. However, here what's inside the bracket (called "key" for objects, instead of "index") must be a string.
13+
14+
```js
15+
console.log(obj.name); // -> 'John'
16+
console.log(obj['name']); // -> 'John'
17+
```
18+
19+
Just like with arrays, you can also use a variable to access properties, as long as these variables are strings. In this case you cannot use the dot-notation!
20+
21+
```js
22+
var ageKey = 'age';
23+
console.log(obj[ageKey]); // -> 24
24+
```
25+
26+
Remember that there is a very big difference between `obj[name]` and `obj["name"]`.
27+
28+
> Note:
29+
>
30+
> Thinking back of arrays, the length of an array can be retrieved by `arr.length`. So as mentioned before, arrays are just like other JavaScript objects. You could even write `arr['length']` to access the `length` property of the array. JavaScript will look: is what we put between brackets a number? Then it is an index and we'll look up the correct array element. If it's a string, it's a key and we will look up the corresponding property.

0 commit comments

Comments
 (0)