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

Skip to content

Commit f7fc742

Browse files
authored
Merge pull request HackYourFuture#15 from remarcmij/master
Text enhancements of REVIEW week 1
2 parents b1d3c3e + ca2633d commit f7fc742

File tree

1 file changed

+89
-44
lines changed

1 file changed

+89
-44
lines changed

Week1/REVIEW.md

Lines changed: 89 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
```
44
This review covers:
5-
• some commands thought by Unmesh in class today
5+
• some commands taught by Unmesh in class today
66
• Intro JavaScript (What is it, where can you use it for)
7-
• Variables [var, let, const]
8-
• Basic Data types [Strings, Numbers, Arrays]
7+
• Variables [var, let, const]
8+
• Basic Data types [Strings, Numbers, Arrays]
99
• Operators
1010
```
1111

@@ -40,7 +40,7 @@ man <COMMAND> : Display manual of the COMMAND
4040

4141
## Variables
4242

43-
A "variable" is a place where you can store information, such as a string, or a number. New variables in JavaScript are declared using one of three keywords: let, const, or var.
43+
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`.
4444

4545
> Think of variables names like **labels** on boxes, while the value of the variable are the **contents** of the box - you could change the contents of a box and leave the label intact, the contents of the boxes can have different types, the boxes should have good labels (a box of books being labeled pens would be very confusing),
4646
>
@@ -50,20 +50,26 @@ A "variable" is a place where you can store information, such as a string, or a
5050

5151
### Variable declaration
5252

53-
Variables are "declared" using the `var`, `let` or `const` keyword:
53+
Variables are "declared" using the `var`, `let` or `const` keyword. In the following example three variables are declared with the names `x`, `foo` and `bar`.
5454

5555
```js
5656
var x;
5757
let foo;
5858
const bar;
5959
```
6060

61+
Note that the chosen names in this example are meaningless (perhaps with the exception of `x`, for instance as part of a mathematical program). You should make an effort to always choose names that best describe what you intend this variable to hold.
62+
63+
### var
64+
65+
Prior to JavaScript ES6 the `var` keyword was the only way to declare a variable. ES6 introduced two new keywords, `let` and `const` for declaring variables. They improve on how the older `var` declaration works (this involves the concept of "scope" that you will learn about in the third lecture). In HackYourFuture we encourage you to use the more modern `let` and `const` keywords over `var`, but you will often come across `var` in existing books, software libraries and examples on the Internet, so you should understand `var` too.
66+
6167
### let and const
6268
- read about [let](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let)
6369
- read about [const](https://developer.mozilla.org/nl/docs/Web/JavaScript/Reference/Statements/const)
64-
- [let vs const] (http://wesbos.com/let-vs-const/)
70+
- [let vs const] (http://wesbos.com/let-vs-const/)
6571

66-
Here, we say: "declare variable x and initialize it with the integer (number) 5".
72+
Here, we say: "declare variable x and initialize it with the integer (number) 6".
6773

6874
```js
6975
let foo; // declare variable `foo`
@@ -79,9 +85,9 @@ foo = 4; // change variable `foo`
7985
```
8086

8187

82-
## Variable types
88+
## Value types
8389

84-
All variables have a type. In our example above, the variable `x` is a `number`. JavaScript supports the following types:
90+
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:
8591

8692
* `string`, e.g. "HackYourFuture"
8793
* `number`, e.g. 5, or 10.6
@@ -90,10 +96,11 @@ All variables have a type. In our example above, the variable `x` is a `number`.
9096
* `object`, e.g. `{name: 'John', age: 24}`, or the special object `null`
9197
* `function`, e.g. `function () { return 4; }`
9298
* `symbol`
99+
* `undefined`
93100

94-
In addition, a variable may be `undefined`. This is also a special type.
101+
If you declare a variable without specifying its value, then, by default its value is `undefined`.
95102

96-
To get the type of a variable, use the following code:
103+
To get the type of a value assigned to a variable, use the following code:
97104

98105
```js
99106
let x = 5;
@@ -107,38 +114,39 @@ let arr = [1, 2, 3];
107114
let typeOfArr = typeof arr; // -> 'object'
108115
```
109116

110-
However, in our communication, we will call these variables arrays.
117+
However, in practice we will call these variables arrays.
111118

112-
### Null & undefined
119+
### Null and undefined
113120

114-
The values `null` and `undefined` are very similar in JavaScript, but they behave a bit differently. The difference is that `null` always has type "object", and `undefined` always has type "undefined".
121+
The values `null` and `undefined` are very similar in JavaScript, but they behave a bit differently. The difference is that `null` always has type `'object'`, and `undefined` always has type `'undefined'`.
115122

116-
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.
123+
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 assign it the value `null`.
117124

118125
```js
119126
let x;
120127
console.log(typeof x); // -> 'undefined'
121128
```
122129

123130

124-
### Typeof
131+
### `typeof` operator
125132

126-
You can use `typeof` to get the type of a certain variable as you have seen in the above section 'Variable types'. As you can see in the following examples it returns the type of data that you have stored in your variable.
133+
You can use the `typeof` operator to get the type of a certain variable as you have seen in the above section 'Value types'. As you can see in the following examples it returns the type of value that you have assigned to your variable.
127134

128135
## Strings
129136

130-
In JavaScript you can store a series of characters inside a variable, you then call this a string. You can store all sorts of characters (text/numbers, spaces or phrases) in strings. By using the `''` you define that something is a string. You can also use `""` to create a string. Both are fine as long as you are consistent (just make a choice on which one you prefer and stick to it).
137+
In JavaScript you can assign a series of characters to a variable, you then call this a string. You can use all sorts of characters (text/numbers, spaces or phrases) in strings. By using the `''` you define that something is a string. You can also use `""` to create a string. Both are fine as long as you are consistent (just make a choice on which one you prefer and stick to it).
131138

132139
```js
133140
let foo = '42';
134141
typeof foo //-> 'string'
135142

136-
let bar = 'I\'m 99 years old ';
143+
let bar = 'I\'m 99 years old ';
137144
typeof bar //-> 'string'
138145
```
139146

140147
### String indexes and string properties
141-
The index of a string always starts at 0.
148+
149+
Individual characters in a string can be accessed by their position (index) within the string. The index of a string always starts at 0.
142150
Strings also have properties, for example `.length` you can use this to find the length of a string.
143151

144152
So for example:
@@ -150,14 +158,30 @@ baz.length; //-> 11
150158

151159
### String methods
152160

153-
>Todo
161+
String methods are named operations that you can use on string values to create new values. For example, the `toUpperCase` method creates a new string with all uppercase letters.
162+
163+
```js
164+
let baz = 'Hello World!';
165+
baz.toUpperCase(); // -> 'HELLO WORLD'
166+
```
167+
168+
Methods differ from properties (such as `.length`) in that you must always use them with open and close parentheses `(` and `)`.
169+
170+
Some methods need additional information, and you must supply it in the form of one or more _parameters_. For example:
171+
172+
```js
173+
let baz = 'Hello World!';
174+
baz.slice(3, 8) // -> 'lo Wo'
175+
baz.startsWith('He') // -> true
176+
baz.indexOf('World') // -> 6
177+
```
154178

155179
## Numbers
156180

157-
All numbers in JavaScript are considered numbers with or without decimal
181+
All numbers in JavaScript are considered numbers, either with or without a decimal.
158182

159183
```js
160-
let quux = 42;
184+
let quux = 42;
161185
typeof quux //-> 'number'
162186

163187
let quuux = 3.3333;
@@ -168,14 +192,14 @@ typeof quuux //-> 'number'
168192

169193
## Arrays
170194

171-
Variables that are arrays contain a list of things, instead of just one thing. What's inside the array, we typically call "elements". So, the array `[1, 2, 3]` has three elements. The array `[]` has no elements and is therefore empty. The number of elements in an array is called its "length".
195+
Arrays are values that contain a list of things, instead of just one thing. What's inside the array, we typically call "elements". So, the array `[1, 2, 3]` has three elements. The array `[]` has no elements and is therefore empty. The number of elements in an array is called its "length".
172196

173197
When you want to access an element inside an array, you use an "index". This is the number that you put between brackets (`[]`).
174198

175199
Given the following code:
176200

177201
```js
178-
var arr = ['john', 'jane', 'jack'];
202+
let arr = ['john', 'jane', 'jack'];
179203
console.log(arr[0]);
180204
```
181205

@@ -193,17 +217,20 @@ If the index you use is not an integer (a whole number), or if it's less than `0
193217

194218
More about [arrays](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)
195219

220+
## Operators
221+
196222
### Comparison operators
197223

198224
>Note the two different uses of the equals sign:
199225
A single equals sign (=) is used to assign a value to a variable.
200226
A triple equals sign (===) is used to compare two values (see Equality Operators).
201227

202228
#### Equality operators
229+
203230
* Equality `==`
204231
* Inequality `!=`
205-
* Identity / strict equality `===`
206-
* Non-identity / strict inequality `!==`
232+
* Identity / strict equality `===` (preferred)
233+
* Non-identity / strict inequality `!==` (preferred)
207234

208235
How does this work in practice?
209236

@@ -219,13 +246,16 @@ How does this work in practice?
219246

220247
> why does `7 == '7'` returns true and `9 === '9'` returns false?
221248
249+
We strongly recommend that you always use the strict form when comparing for equality (`===`) or inequality (`!==`). Use the non-strict forms only when there is a compelling reason to do so (you will be hard pressed to find such a reason).
250+
222251
#### Relational operators
252+
223253
* Greater than operator `>`
224254
* Greater than or equal operator `>=`
225255
* Less than operator `<`
226256
* Less than or equal operator `<=`
227257

228-
```js
258+
```js
229259
4 > 3 // -> true
230260
3 >= 3 // -> true
231261
13 < 12 // -> false
@@ -239,49 +269,64 @@ More about [comparison operators](https://developer.mozilla.org/en-US/docs/Web/J
239269
* Addition `+`
240270
* Subtraction `-`
241271
* Multiplication `*`
242-
* Division `/`
243-
* Remainder (sometimes called modulo) `%`
272+
* Division `/`
273+
* Remainder (sometimes called modulo) `%`
244274
<br>Returns the remainder left over after you've shared the left number out into a number of integer portions equal to the right number.
245275

246276
```js
247-
8 + 9 // -> 17, adds two numbers together.
277+
8 + 9 // -> 17, adds two numbers together.
248278
20 - 12 // -> 8, subtracts the right number from the left.
249279
3 * 4 // -> 12, multiplies two numbers together.
250-
10 / 5 // -> 2, divides the left number by the right.
280+
10 / 5 // -> 2, divides the left number by the right.
251281
8 % 3 /// -> 2, as three goes into 8 twice, leaving 2 left over.
252282
```
253283

254-
More about [Arithmetic_Operators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#.25_.28Modulus.29)
284+
More about [Arithmetic operators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#.25_.28Modulus.29)
255285

256286
### Logical operators
257287

258288
* AND `&&`
259-
* OR `||`
289+
* OR `||`
260290
* NOT `!`
261291

262292
Given that x = 6 and y = 3
263293
```js
264294
x < 10 && y > 1 // -> true
265-
x == 5 || y == 5 // -> false
295+
x === 5 || y === 5 // -> false
266296
x !== y // -> true
267297
```
268298

299+
Logical NOT
300+
301+
```js
302+
true === !false
303+
false === !true
304+
```
305+
269306
More about [logical operators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators)
270307

271-
### Operator precedence
308+
### typeof operator
309+
310+
We already mentioned the `typeof` operator:
311+
312+
```js
313+
typeof 5 // -> 'number'
314+
```
315+
316+
### Assignment operators
272317

273-
There are compound assignment operators such as +=. The following two assignments are equivalent:
318+
In addition to the simple assignment operator `=` there are also compound assignment operators such as `+=`. The following two assignments are equivalent:
274319

275320
```js
276321
x += 1;
277322
x = x + 1;
278323
```
279324

280325
|Operator| Example| Same As|
281-
-----------------------------
282-
|= | x = y| x = y|
283-
|+=| x += y| x = x + y|
284-
|-=| x -= y| x = x - y|
285-
|*=| x *= y| x = x * y|
286-
|/=| x /= y| x = x / y|
287-
|%=| x %= y| x = x % y|
326+
|:------:|:--------:|:-------:|
327+
|`=` | `x = y` | `x = y`|
328+
|`+=`| `x += y` | `x = x + y`|
329+
|`-=`| `x -= y` | `x = x - y`|
330+
|`*=`| `x *= y` | `x = x * y`|
331+
|`/=`| `x /= y` | `x = x / y`|
332+
|`%=`| `x %= y` | `x = x % y`|

0 commit comments

Comments
 (0)