You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
echo “something” > file : Redirect the output of echo and create file
21
-
echo “another thing” >> file : Append the string to the file
22
-
mkdir: make a new directory
23
-
cd ~ : home
24
-
cd - : previous directory
25
-
cd .. : parent directory
26
-
ls -a : List all files including hidden files
27
-
cd / : change to the root directory
28
-
cat : Concatenate the file line by line and display it on the terminal
29
-
less: Print the big file line by line
30
-
vim <file> : open the editor with <file> {a: to go to the insert mode, <ESC>:wq to write and quit }
31
-
for var in {START..END}; do <COMMAND1>; <COMMAND2>;..; ; done
32
-
head <file>: display the first 10 lines of file
33
-
tail <file>: display the last 10 lines of file
34
-
head -n <file> : display first n lines of file
35
-
tail -n <file> : display last n lines of file
36
-
man <COMMAND> : Display manual of the COMMAND
37
-
```
38
-
39
-
: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
40
-
41
-
## Variables
42
-
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`.
44
-
45
-
> 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),
46
-
>
47
-

48
-
> Photo from [Khan Academy](http://cs-blog.khanacademy.org/2013/09/teaching-variables-analogies-and.html)
49
-
50
-
51
-
### Variable declaration
52
-
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`.
54
-
55
-
```js
56
-
var x;
57
-
let foo;
58
-
constbar;
59
-
```
60
-
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
13
63
-
### var
14
+
Command Line Interface
64
15
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.
16
+
[Read more...](../topics/CLI.md)
66
17
67
-
### let and const
68
-
- read about [let](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let)
69
-
- read about [const](https://developer.mozilla.org/nl/docs/Web/JavaScript/Reference/Statements/const)
70
-
-[let vs const] (http://wesbos.com/let-vs-const/)
18
+
>: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
71
19
72
-
Here, we say: "declare variable x and initialize it with the integer (number) 6".
73
-
74
-
```js
75
-
let foo; // declare variable `foo`
76
-
```
77
-
78
-
```js
79
-
let foo =6; // declare and assign a variable at the same time
80
-
```
20
+
## Variables
81
21
82
-
You can also assign a value to an existing variable:
83
-
```js
84
-
foo =4; // change variable `foo`
85
-
```
22
+
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`.
86
23
24
+
[Read more...](../topics/variables.md)
87
25
88
-
## Value types
26
+
## Values
89
27
90
28
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:
91
29
92
-
*`string`, e.g. "HackYourFuture"
93
-
*`number`, e.g. 5, or 10.6
94
-
*`boolean`, e.g. `true` or `false`
95
-
*`array`\*, e.g. `[1, 2, 3]` or `['what', 'is', 'your', 'name']`
96
-
*`object`, e.g. `{name: 'John', age: 24}`, or the special object `null`
97
-
*`function`, e.g. `function () { return 4; }`
98
-
*`symbol`
99
-
*`undefined`
100
-
101
-
If you declare a variable without specifying its value, then, by default its value is `undefined`.
102
-
103
-
To get the type of a value assigned to a variable, use the following code:
104
-
105
-
```js
106
-
let x =5;
107
-
let typeOfX =typeof x; // -> 'number'
108
-
```
109
-
110
-
Note that I've put an asterisk behind 'array'. That is because in JavaScript, array is a special kind of object:
111
-
112
-
```js
113
-
let arr = [1, 2, 3];
114
-
let typeOfArr =typeof arr; // -> 'object'
115
-
```
116
-
117
-
However, in practice we will call these variables arrays.
118
-
119
-
### Null and undefined
120
-
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'`.
122
-
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`.
124
-
125
-
```js
126
-
let x;
127
-
console.log(typeof x); // -> 'undefined'
128
-
```
129
-
130
-
131
-
### `typeof` operator
132
-
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.
134
-
135
-
## Strings
136
-
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).
138
-
139
-
```js
140
-
let foo ='42';
141
-
typeof foo //-> 'string'
142
-
143
-
let bar ='I\'m 99 years old ';
144
-
typeof bar //-> 'string'
145
-
```
146
-
147
-
### String indexes and string properties
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.
150
-
Strings also have properties, for example `.length` you can use this to find the length of a string.
151
-
152
-
So for example:
153
-
```js
154
-
let baz ='Hello World';
155
-
baz[0]; //-> "H"
156
-
baz.length; //-> 11
157
-
```
158
-
159
-
### String methods
160
-
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
-
```
178
-
179
-
## Numbers
180
-
181
-
All numbers in JavaScript are considered numbers, either with or without a decimal.
182
-
183
-
```js
184
-
let quux =42;
185
-
typeof quux //-> 'number'
186
-
187
-
let quuux =3.3333;
188
-
typeof quuux //-> 'number'
189
-
190
-
```
191
-
192
-
193
-
## Arrays
194
-
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".
196
-
197
-
When you want to access an element inside an array, you use an "index". This is the number that you put between brackets (`[]`).
198
-
199
-
Given the following code:
200
-
201
-
```js
202
-
let arr = ['john', 'jane', 'jack'];
203
-
console.log(arr[0]);
204
-
```
205
-
206
-
The number `0` is the "index of the first element of array `arr`". Conversely, the element "at index 0 in array `arr` is `'john'`".
207
-
208
-
Instead of a number, you can also use a variable to access elements in an array, *as long as this variable is a number*:
209
-
210
-
```js
211
-
let arr = ['john', 'jane', 'jack'];
212
-
let a =1;
213
-
console.log(arr[a]); // -> jane
214
-
```
215
-
216
-
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`.
217
-
218
-
More about [arrays](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)
30
+
[Read more...](../topics/values.md)
219
31
220
32
## Operators
221
33
222
-
### Comparison operators
223
-
224
-
>Note the two different uses of the equals sign:
225
-
A single equals sign (=) is used to assign a value to a variable.
226
-
A triple equals sign (===) is used to compare two values (see Equality Operators).
> why does `7 == '7'` returns true and `9 === '9'` returns false?
248
-
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
-
251
-
#### Relational operators
252
-
253
-
* Greater than operator `>`
254
-
* Greater than or equal operator `>=`
255
-
* Less than operator `<`
256
-
* Less than or equal operator `<=`
257
-
258
-
```js
259
-
4>3// -> true
260
-
3>=3// -> true
261
-
13<12// -> false
262
-
3<=4// -> true
263
-
```
264
-
265
-
More about [comparison operators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators)
266
-
267
-
### Arithmetic operators
268
-
269
-
* Addition `+`
270
-
* Subtraction `-`
271
-
* Multiplication `*`
272
-
* Division `/`
273
-
* Remainder (sometimes called modulo) `%`
274
-
<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.
275
-
276
-
```js
277
-
8+9// -> 17, adds two numbers together.
278
-
20-12// -> 8, subtracts the right number from the left.
279
-
3*4// -> 12, multiplies two numbers together.
280
-
10/5// -> 2, divides the left number by the right.
281
-
8%3/// -> 2, as three goes into 8 twice, leaving 2 left over.
282
-
```
283
-
284
-
More about [Arithmetic operators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#.25_.28Modulus.29)
285
-
286
-
### Logical operators
287
-
288
-
* AND `&&`
289
-
* OR `||`
290
-
* NOT `!`
291
-
292
-
Given that x = 6 and y = 3
293
-
```js
294
-
x <10&& y >1// -> true
295
-
x ===5|| y ===5// -> false
296
-
x !== y // -> true
297
-
```
298
-
299
-
Logical NOT
300
-
301
-
```js
302
-
true===!false
303
-
false===!true
304
-
```
305
-
306
-
More about [logical operators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators)
307
-
308
-
### typeof operator
309
-
310
-
We already mentioned the `typeof` operator:
311
-
312
-
```js
313
-
typeof5// -> 'number'
314
-
```
315
-
316
-
### Assignment operators
317
-
318
-
In addition to the simple assignment operator `=` there are also compound assignment operators such as `+=`. The following two assignments are equivalent:
0 commit comments