-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascript.html
More file actions
174 lines (131 loc) · 6.74 KB
/
javascript.html
File metadata and controls
174 lines (131 loc) · 6.74 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>
Hillary Sanders
</title>
<meta name="author" content="Hillary Sanders">
<meta name="keywords" content="Hillary Sanders Statistics Berkeley Premise Data Scientist Art Bayesian Painting">
<meta name="description" content="Hillary Sanders: Data Scientist?">
<meta name="robots" content="index, follow, noarchive">
<link type="text/css" rel="stylesheet" href="css/reset.css"/>
<link type="text/css" rel="stylesheet" href="css/mainstylesheet.css"/>
<style>
.midwrap {
min-height: 1800px;
}
.light {
min-height: 1525px;
}
</style>
</head>
<body>
<div class="midwrap">
<div class="header codex basic"><h1>hillary sanders</h1></div>
<div class="navbox">
<ul class="navlist">
<a href="index.html"><li class="navitem basic">about hillz</li></a>
<a href="drawings.html"><li class="navitem basic">drawings</li></a>
<a href="paintings.html"><li class="navitem basic">paintings</li></a>
<a href="mixed-media.html"><li class="navitem basic">mixed media</li></a>
<a href="cheatsheets.html"><li class="navitem basic breadcrumb">cheatsheets</li></a>
<a href="code.html"><li class="navitem basic">code</li></a>
<a href="graphs.html"><li class="navitem basic">graphs</li></a>
<a href="resume.html"><li class="navitem basic">resume</li></a>
</ul>
</div>
<div class="navbox navbox">
<ul class="navlist-mini">
<a href="emacs.html"><li class="navitem-mini basic">Emacs</li></a>
<a href="python.html"><li class="navitem-mini basic">Python</li></a>
<a href="scala.html"><li class="navitem-mini basic">Scala</li></a>
<a href="latex.html"><li class="navitem-mini basic">LaTeX</li></a>
<a href="UNIX.html"><li class="navitem-mini basic">UNIX</li></a>
<a href="javascript.html"><li class="navitem-mini basic breadcrumb">Javascript</li></a>
<a href="probability_theory.html"><li class="navitem-mini basic">Probability</li></a>
<a href="bayesian_analysis.html"><li class="navitem-mini basic">Bayesian Stats</li></a>
</ul>
</div>
<!-- Main content -->
<!-- Main content -->
<div class="onecol">
<h2><b>Javascript</b></h2>
</div>
<div class="midwrap light">
<div class="threecol thick">
<h2> <b>Data Structures</b> </h2>
<h3>Numbers</h3>
- Includes integers, <code>+infinity</code> and <code>-infinity</code>, and <code>NaN</code> (not a number)<br>
- Numbers can be a bit weird in javascript because not a lot of digits are stored in memory.
While<br> <code> 0.1 + 0.2 == 0.30000000000000004 </code> returns <code> true, <br> </code>
<code>0.1 + 0.2 == 0.3000000000000004</code> (one less zero) returns <code>false</code>.
<br> <br>
There's a built-in object called <code>Math</code> that helps out with a few mathematical functions and constants.
<br>
<code>Math.sin(0)</code><comment> // 0</comment><br>
<code>Math.round(Math.exp(2))</code> <comment> // 7 </comment><br>
<code>Math.pi</code> <comment> // 3.141592653589793 </comment><br>
<br>
There are built in functions that can, for example, convert characters to integers (the 10 = the base).<br>
<code>parseInt("123", 10)</code> <comment> // 123</comment><br>
<code>parseInt("ummm")</code> <comment> // NaN </comment><br>
<code>+"10"</code> <comment> // 10</comment><br>
<h3>Strings</h3>
substr(begin, length)<br>
<code> 'hello world!'.substr(6, 5) </code> <comment> // "world" </comment><br>
<code> "hello".charAt(0)</code> <comment> // "h" </comment><br>
<code> "Eww, ice cream".replace("Eww,", "I like") </code> <comment> // "I like ice cream"</comment><br>
<code> "hello".toUpperCase()</code> <comment> // "HELLO"</comment><br>
<code> "ice" + " " + "cream"</code> <comment> // "ice cream"</comment><br>
Note that when coercing numbers to characters, order matters. If the numbers come first, they'll be
added together before being coerced to characters.
<code>"1" + 2 + 3 </code> <comment> // "123" </comment><br>
<code> 2 + 3 + "1" </code> <comment> // "51"</comment><br>
<h3>Booleans</h3>
<code>false</code>: <code>false</code>, <code>0</code>, the empty string <code>""</code>, <code>NaN</code>, <code>null</code>, and <code>undefined</code> all become false.
<br>
<code>true</code>: everything else. <br>
<h4>Comparisons:</h4>
<code><</code>, <code>></code>, <code><=</code>, <code>>=</code>, <code>==</code>, <code>===</code>, <code>!=</code>
<code>1==true</code> <comment> // True</comment><br>
<code>1===true </code> <comment> // False</comment><br>
<code>1===1</code> <comment> // True</comment><br>
<h3>Undefined</h3>
An unititialized value. If you declare a variable without assigning a value to it, it will be <code>Undefined</code>.
<h3>Null</h3>
A deliberate non-value.
<h3>Objects</h3>
<li> <h3> Functions</h3></li>
<li> <h3> Arrays</h3></li>
<li> <h3> Dates</h3></li>
<li> <h3> Regular Expressions</h3></li>
<code> </code> <comment> // </comment><br>
<code> var a = 4</code> <comment> </comment><br>
</div>
<div class="threecol thick">
</div>
<div class="threecol thick" id="js">
<center>
<input type="text" id="typey_box"/>
<button onclick="do_things()">Click</button>
<div id="output">Results will appear here.</div>
</center>
</div>
</div>
</div>
</body>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script>
function do_things()
{
var text_box = document.getElementById('typey_box');
var results_box = document.getElementById('output');
var text = text_box.value;
var message = 1+2==3.00000000000000004
var message = "I dislike ice cream".replace("dislike", "like")
results_box.innerHTML = message;
}
document.write('<b>Hello World</b>');
</script>
</html>