Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 72f3d1a

Browse files
committed
added review week2
1 parent f3737ed commit 72f3d1a

File tree

3 files changed

+174
-14
lines changed

3 files changed

+174
-14
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ Here you can find course content and homework for the JavaScript 1,2 and 3 modul
88
|Week|Topic|Read|Homework|
99
|----|-----|----|--------|
1010
|0.|Preparation for your first JavaScript session|[Pre-reading](https://github.com/HackYourFuture/JavaScript/tree/master/Week0) + [CLI Reading Week 1](https://github.com/HackYourFuture/CommandLine/blob/master/Lecture-1.md)|-|
11-
|1.|[CLI](https://github.com/HackYourFuture/CommandLine) session with Unmesh :heart: • Intro JavaScript (What is it, where can you use it for)<br>• Variables [var, let, const]<br>• Basic Data types [Strings, Numbers, Arrays]<br>• Operators| TBA | [Homework Week 1](https://github.com/HackYourFuture/JavaScript/tree/master/Week1/MAKEME.md) + [CLI Homework Week 1](https://github.com/HackYourFuture/CommandLine/blob/master/HomeWork.md)|
12-
|2.|[CLI](https://github.com/HackYourFuture/CommandLine) session with Unmesh :balloon: <br>• Conditions <br>• Naming conventions <br> • Loops (for/while)<br>• Functions <br>• Closures <br>• Scope |[Reading Week 2](https://github.com/HackYourFuture/JavaScript/tree/master/Week2)|[JS](https://github.com/HackYourFuture/JavaScript/tree/master/Week2/MAKEME.md)|
13-
|3.|• Advanced data types [Objects] <br>• Array Manipulations <br>• Basic DOM manipulations [img src, innerHTML]<br>• Code commenting|[Reading Week 3](https://github.com/HackYourFuture/JavaScript/tree/master/Week3)|[Homework Week 3](https://github.com/HackYourFuture/JavaScript/tree/master/Week3/MAKEME.md)|
11+
|1.|[CLI](https://github.com/HackYourFuture/CommandLine) session with Unmesh :heart: <br>• Intro JavaScript (What is it, where can you use it for)<br>• Variables [var, let, const]<br>• Basic Data types [Strings, Numbers, Arrays]<br>• Operators| TBA | [Homework Week 1](https://github.com/HackYourFuture/JavaScript/tree/master/Week1/MAKEME.md) + [CLI Homework Week 1](https://github.com/HackYourFuture/CommandLine/blob/master/HomeWork.md)|
12+
|2.|[CLI](https://github.com/HackYourFuture/CommandLine) session with Unmesh :balloon: <br>• Conditions <br>• Statements vs Expressions<br> • Loops (for/while)<br>• Functions <br>• Naming conventions|[Reading Week 2](https://github.com/HackYourFuture/JavaScript/tree/master/Week2)|[Homework week 2](https://github.com/HackYourFuture/JavaScript/tree/master/Week2/MAKEME.md)|
13+
|3.|• Advanced data types [Objects] <br>• Closures <br>• Scope <br>• Array Manipulations <br>• Basic DOM manipulations [img src, innerHTML]<br>• Code commenting|[Reading Week 3](https://github.com/HackYourFuture/JavaScript/tree/master/Week3)|[Homework Week 3](https://github.com/HackYourFuture/JavaScript/tree/master/Week3/MAKEME.md)|
1414
|4.|• First Git Session with Unmesh :smiling_imp:<br>• JSON<br>• Code debugging using the browser<br>• Functions + JSON/Arrays<br>• Code flow (order of execution) <br>• (capturing user input) <br>• Structuring code files|[Reading Week 4](https://github.com/HackYourFuture/JavaScript/tree/master/Week4)|[JS](https://github.com/HackYourFuture/JavaScript/tree/master/Week4/MAKEME.md) + [Git Homework Week 4](https://github.com/HackYourFuture/Git/blob/master/Lecture-1.md)|
1515
|5.|• Second Git Session :see_no_evil:<br>• Events<br>• Callbacks <br>• XHTTP Requests <br>• API calls|[Reading Week 5](https://github.com/HackYourFuture/JavaScript/tree/master/Week5)|[Homework Week 5](https://github.com/HackYourFuture/JavaScript/tree/master/Week5/MAKEME.md) |
1616
|6.|• Async VS Sync <br>• Polling<br>• Structure for a basic SPA <br> TEST :boom:|[Reading Week 6](https://github.com/HackYourFuture/JavaScript/tree/master/Week6)|[Homework Week 6](https://github.com/HackYourFuture/JavaScript/tree/master/Week6/MAKEME.md)|

Week1/REVIEW.md

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# REVIEW JavaScript Basics
1+
# REVIEW JavaScript Basics week 1
22

33
## Variables
44

@@ -17,9 +17,7 @@ const bar;
1717
### let and const
1818
- read about [let](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let)
1919
- read about [const](https://developer.mozilla.org/nl/docs/Web/JavaScript/Reference/Statements/const)
20-
- [let vs const] (http://wesbos.com/let-vs-const/)
21-
22-
>TODO - reconsider resources.
20+
- [let vs const] (http://wesbos.com/let-vs-const/)
2321

2422
Here, we say: "declare variable x and initialize it with the integer (number) 5".
2523

@@ -54,15 +52,15 @@ In addition, a variable may be `undefined`. This is also a special type.
5452
To get the type of a variable, use the following code:
5553

5654
```js
57-
var x = 5;
58-
var typeOfX = typeof x; // -> "number"
55+
let x = 5;
56+
let typeOfX = typeof x; // -> "number"
5957
```
6058

6159
Note that I've put an asterisk behind 'array'. That is because in JavaScript, array is a special kind of object:
6260

6361
```js
64-
var arr = [1, 2, 3];
65-
var typeOfArr = typeof arr; // -> "object"
62+
let arr = [1, 2, 3];
63+
let typeOfArr = typeof arr; // -> "object"
6664
```
6765

6866
However, in our communication, we will call these variables arrays.
@@ -74,7 +72,7 @@ The values `null` and `undefined` are very similar in JavaScript, but they behav
7472
Whenever you declare a variable, but you don't set a value, the variable will become `undefined`. JavaScript will never make a variable `null` unless you explicitly program it.
7573

7674
```js
77-
var x;
75+
let x;
7876
console.log(typeof x); // -> "undefined"
7977
```
8078

@@ -97,11 +95,27 @@ The number `0` is the "index of the first element of array `arr`". Conversely, t
9795
Instead of a number, you can also use a variable to access elements in an array, *as long as this variable is a number*:
9896

9997
```js
100-
var arr = ['john', 'jane', 'jack'];
101-
var a = 1;
98+
let arr = ['john', 'jane', 'jack'];
99+
let a = 1;
102100
console.log(arr[a]); // -> jane
103101
```
104102

105103
If the index you use is not an integer (a whole number), or if it's less than `0` or if it's greater than or equal to the array's length, you will get back `undefined`.
106104

107105

106+
### 2.3 Basic operators
107+
108+
>Note the two different uses of the equals sign:
109+
A single equals sign (=) is used to assign a value to a variable.
110+
A triple equals sign (===) is used to compare two values (see Equality Operators).
111+
112+
### 2.5 Operator precedence
113+
114+
There are compound assignment operators such as +=. The following two assignments are equivalent:
115+
116+
```js
117+
x += 1;
118+
x = x + 1;
119+
```
120+
121+

Week2/REVIEW.md

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# REVIEW JavaScript week 2
2+
3+
## Statements & expressions
4+
5+
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.
6+
7+
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.
8+
9+
Similarly, a statement in JavaScript should provide a command by itself. JavaScript-statements are (almost always) terminated by a semicolon.
10+
11+
This is a complete statement:
12+
13+
```js
14+
let s = "HackYourFuture";
15+
```
16+
17+
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.
18+
19+
However, this is not a complete statement:
20+
21+
```js
22+
4 + 5
23+
```
24+
25+
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.
26+
27+
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.
28+
29+
### Examples of expressions
30+
31+
Here are some examples of expressions. Remember: expressions evaluate into a value, but do not provide a command:
32+
33+
* `sum(a, b)`
34+
* `a`
35+
* `a > 4 ? "yes" : "no"`
36+
* `a + b`
37+
* `a && b || c`
38+
* `arr.length`
39+
* `obj["name"]`
40+
* `[1, 2, 3]`
41+
* `arr[1]`
42+
* `[1]` (this is an array with one element!)
43+
* `function a() { return 4; }`
44+
45+
The last one requires a bit of explanation. If you write:
46+
47+
```js
48+
function a() { return 4; }
49+
```
50+
51+
by itself, this is a *statement* (a function declaration statement). However, if you write it as part of a statement, such as:
52+
53+
```js
54+
let b = function a() { return 4; }
55+
```
56+
57+
now it is an expression. This is an exceptional situation where something can be a statement or an expression.
58+
59+
### Examples of not-expressions
60+
61+
The following are not expressions:
62+
63+
* `var` -> this is a keyword, see below
64+
* `var x;` -> this is a statement
65+
* `+` -> this is only an operator
66+
* `if (a > 4) { return "yes"; } else { return "no"; }`
67+
68+
`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.
69+
70+
## Functions
71+
72+
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*.
73+
74+
The following two pieces of code have the exact same result:
75+
76+
```js
77+
function sum(a, b) {
78+
return a + b;
79+
}
80+
```
81+
82+
and
83+
84+
```js
85+
let sum = function (a, b) {
86+
return a + b;
87+
}
88+
```
89+
90+
> Note
91+
>
92+
> 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)`.
93+
94+
### Parameters & arguments
95+
96+
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.)
97+
98+
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`".
99+
100+
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:
101+
102+
* A parameter is the name you want to give to the variable that is available inside of the function.
103+
* An argument is the actual value you want to assign to the parameters when you call the function.
104+
105+
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.
106+
107+
### Calling a function on something
108+
109+
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:
110+
111+
```js
112+
let s = " this is a string ";
113+
s.trim(); // -> "this is a string"
114+
```
115+
116+
> Note
117+
>
118+
> Technically, this means that the string `s` will become the `this` special variable inside of the function.
119+
120+
However, there are functions that you don't call on anything:
121+
122+
```js
123+
function sum(a, b) { return a + b; }
124+
sum(4, 5); // -> 9
125+
```
126+
127+
Here, you call the function `sum` on nothing.
128+
129+
Most built-in functions in JavaScript, like math functions or logging functions, also use the dot:
130+
131+
```js
132+
Math.round(4.5);
133+
console.log("hello");
134+
Array.from([1, 2, 3]);
135+
```
136+
137+
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.
138+
139+
It's more when you think about which functions you can call "on" your own variables (strings, arrays, numbers, etc):
140+
141+
```js
142+
myString.trim();
143+
myArray.slice();
144+
myNumber.toString();
145+
...
146+
```

0 commit comments

Comments
 (0)