3
3
javascript is a programming language
4
4
you can use to program web pages
5
5
and command-line tools and servers
6
+
6
7
---
7
8
# install node
8
9
@@ -12,6 +13,7 @@ to learn javascript.
12
13
Download and install node from:
13
14
14
15
https://nodejs.org
16
+
15
17
---
16
18
# write a program
17
19
@@ -48,6 +50,7 @@ Note the single quotes on each side.
48
50
You can use double quotes too: ` "BEEP BOOP" `
49
51
50
52
Sometimes an "argument" is called a "parameter".
53
+
51
54
---
52
55
# statements
53
56
@@ -85,6 +88,7 @@ is rare in practice.
85
88
86
89
Both including and omitting semicolons
87
90
are popular code styles.
91
+
88
92
---
89
93
# variables
90
94
@@ -115,6 +119,7 @@ Variables are containers that can hold values.
115
119
116
120
Strings like ` 'beep' ` and numbers like ` 5 `
117
121
are values.
122
+
118
123
---
119
124
# operators
120
125
@@ -150,6 +155,7 @@ Then type an expression and you will see its result:
150
155
```
151
156
152
157
Type ctrl+d to exit the REPL.
158
+
153
159
---
154
160
# assignment updates
155
161
@@ -191,6 +197,7 @@ do an update "in place":
191
197
* ` *= ` - multiply in place
192
198
* ` /= ` - divide in place
193
199
* ` %= ` - modulo in place
200
+
194
201
---
195
202
# increment, decrement
196
203
@@ -205,6 +212,7 @@ Same as: `x += 1` or `x = x + 1`
205
212
You might also see ` ++x ` and ` --x ` which
206
213
are similar to ` x++ ` and ` x-- ` but have
207
214
slightly different uses. More on them later.
215
+
208
216
---
209
217
# booleans
210
218
@@ -228,6 +236,7 @@ You might also see coercive equality operators:
228
236
229
237
but you should avoid these operators until
230
238
learning about type coercion.
239
+
231
240
---
232
241
# comparison operators: example
233
242
@@ -437,14 +446,14 @@ if (true) {
437
446
---
438
447
# first rule of indentation
439
448
440
- However you choose to indent,
441
- be consistent!
449
+ However you choose to indent, be consistent!
442
450
443
451
Your code will be much easier for others and yourself to
444
452
read.
445
453
446
454
Remember to line up closing braces at the same level as
447
455
opening statements!
456
+
448
457
---
449
458
# arrays
450
459
@@ -533,6 +542,7 @@ been defined by the language itself.
533
542
534
543
Later we'll see how to inspect what
535
544
methods are available.
545
+
536
546
---
537
547
# arrays: pop
538
548
@@ -703,6 +713,7 @@ var obj = {
703
713
704
714
This way of building objects is sometimes called
705
715
"object literal" syntax.
716
+
706
717
---
707
718
# objects: pick out a single record
708
719
@@ -815,6 +826,7 @@ prints:
815
826
816
827
Everything we can do with dot (updates, assignment
817
828
operators, etc) works with square bracket notation.
829
+
818
830
---
819
831
# objects: delete
820
832
@@ -834,6 +846,7 @@ prints:
834
846
835
847
If you try to delete a key that doesn't exist, nothing
836
848
happens.
849
+
837
850
---
838
851
# Object.keys
839
852
@@ -1295,6 +1308,7 @@ BEEP BOOP
1295
1308
* number to hex string: ` (123).toString(16) === '7b'
1296
1309
* binary string to number: ` parseInt (' 1111011' ,2 ) === 123 `
1297
1310
* hex string to number: ` parseInt (' 7b' ,16 ) === 123 `
1311
+
1298
1312
---
1299
1313
# JSON: stringify
1300
1314
@@ -1356,6 +1370,7 @@ prints:
1356
1370
log base 2 of 255 = ` Math .log (255 ) / Math .log (2 )`
1357
1371
1358
1372
[read more](http://mzl.la/148HnQj)
1373
+
1359
1374
---
1360
1375
# builtin: Date
1361
1376
@@ -1391,6 +1406,7 @@ console.log([ d.getFullYear(), d.getMonth(), d.getDay() ])
1391
1406
1392
1407
console .log ([ d .getHours (), d .getMinutes (), d .getSeconds () ])
1393
1408
// [ 10, 18, 26 ]
1409
+ ` ` `
1394
1410
---
1395
1411
# homework
1396
1412
0 commit comments