-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascript-notes.txt
More file actions
111 lines (96 loc) · 2.2 KB
/
javascript-notes.txt
File metadata and controls
111 lines (96 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// is a single line comment
/* */ is a multi line comment but it is unsafe because the */ pair may occur in a regex
reserved names -- not all of these are actually used, but you can't use any of them;
break
case
class
catch
const
continue
debugger
default
delete
do
else
export
extends
finally
for
function
if
import
in
instanceof
let
new
return
super
switch
this
throw
try
typeof
var
void
while
with
yield
strings can be created using single or double quotes, there is no char type.
Two strings with the same charecters in the same order have the same value;
"foo" === "f" + "o" + "o";
strings all have a length property
"nine".length === 4;
strings have methods
"foo".toUpperCase() === "FOO";
all numbers are 64-bit floating point numbers 1 and 1.0 are the same value
declare variables with the var keyword, var age = 99;
All variables are thrown together in the global namespace... this is a serious problem with JavaScript, blocks of code {} also dont have local namespaces, even though they definately should.
Thankfully functions have a local scope, you'll want to get used to taking advantage of this fact early on.
If you foolishly declare a varibale without using the var keyword it will be thrown into the global namespace... don't do this.
comparison operators:
<
=<
>
=>
===
!==
== and != are unreliable because of 'type coersion' always use === and !==
falsey values:
There are rather many values that evalute to false;
false
null
undefined
the empty string '' or ""
the number 0
the number NaN
all other values are truthy, including true, the string "false" and all objects.
selection:
JavaScript has all the usual suspects
if (condition1) {
// do stuff
} else if (condition2) {
// do other stuff
} else {
// last resort
}
switch (variable) {
case "foo":
statements;
break;
case "bar":
statements;
break;
case "baz":
statements;
break;
default:
statements;
}
loops:
c style do .. while and for loops
while ( condition ) {
// keep doing things
}
for (var i = 0; i < someLimit; i++) {
//do something someLimit many times
}