-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjavascript.html
325 lines (218 loc) · 11.5 KB
/
javascript.html
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Pocket Survival Guide - javascript</title>
<link rel="stylesheet" href="psg.css" type="text/css">
<LINK REL="SHORTCUT ICON" HREF="favicon.ico" type="image/x-icon"/>
<META NAME="description" content="System Administrator Pocket Survival Guide - A series of notes for Sys Admin"/>
<META NAME="keyword" content="Sys Admin, System Administrator, Solaris, HP-UX, AIX, Linux, Note, Notes, Pocket, Survival, Guide, psg, data center, power, electrical, plug, LYS, LKS, LAPPLAPP"/>
<META NAME="Robots" CONTENT="all"/>
<META NAME="Author" CONTENT="Tin Ho"/>
<!-- old google analytics tracker at bottom, which is likely reg to dropbox posting -->
<!-- Global site tag (gtag.js) - Google Analytics - t6@g new property for psg-github site -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-4515095-6"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-4515095-6');
</script>
</head>
<body>
<div class="navheader">
<table summary="Navigation header" width="100%">
<tbody>
<tr>
<th colspan="4" align="center">
<A HREF="http://tin6150.github.io/psg/">Sys Admin Pocket Survival Guide - JavaScript</A>
</th>
</tr>
<tr>
<td align="left"><a accesskey="h" href="psg.html">Home</a></td>
<td align="center"><a accesskey="y" href="python.html">Python</a></td>
<td align="center"><a accesskey="j" href="javascript.html">javascript</a></td>
<td align="center"><a accesskey="p" href="php.txt">PHP</a></td>
<td align="center"><a accesskey="l" href="perl.html">Perl</a></td>
<td align="center"><a accesskey="S" href="shellScript.txt">shellScript</a></td>
<td align="center"><a accesskey="s" href="sourceControl.html">sourceControl</a></td>
<td align="right"><a accesskey="g" href="git.html">git</a></td>
</tr>
</tbody>
</table>
<hr></div>
<div class="chapter" lang="en">
<div class="titlepage">
</div>
</div>
<div align="CENTER">
<A HREF="http://www.explainxkcd.com/wiki/index.php/1854"><IMG SRC="fig/xkcd_refresh_types.png" title="The hardest refresh requires both a Mac keyboard and a Windows keyboard as a security measure, like how missile launch systems require two keys to be turned at once." alt="Refresh Types"></A><BR>
</div>
<H1>JavaScript</H1>
<H2>101</H2>
<PRE>
aka Ecma Script.
ES5? ES6? ES7?
may still want to move it back to psg as javascript.html
tba
JS is weakly typed.
a = 1;
b = 1;
( a == b ) // this works
( a === b ) // comparison operator is === , or at least Mozilla Dev Net use this.
https://codeburst.io/javascript-essentials-types-data-structures-3ac039f9877b
6 types of primitive data types:
typeof true // boolean
typeof false // boolean
logical operators: && ||
typeof null // object!! rtfm!
typeof undefined // undefined
Symbols // everything are different.
typeof 1.5 // number
typeof NaN // number WTF?? :)
typeof Infinity // number
typeof 'a' // string
everything else is ojbect. eg hash, function, etc.
there is a concept of strict mode, which change behavior for mixed data types
Hash:
* http://www.mojavelinux.com/articles/javascript_hashes.html
* https://stackoverflow.com/questions/1208222/how-to-do-associative-array-hashing-in-javascript
Object:
- {}
- var myObj = {};
JSON (java script object notation):
- often a list (array) of objects.
- a way to serialize list as communication encoding in API (eg REST calls).
- HOW to refer to individual elements??? D3js seems to represent things in JSON as well...
</PRE>
<H5>Arrays</H5>
<A HREF="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array</A>
<PRE>
Note that Array is a (?) list construct (?) and not a data type.
so, can have an array of any of the data type.
[ 'a', 'b' ] + [ 'c' , 'd' ] //
var fruits = ['Apple', 'Banana'];
fruits.length ; // 2
# loop over an array
fruits.forEach(function(item, index, array) {
console.log(item, index);
});
// Apple 0
// Banana 1
fruits[0]; // Apple, ie 0-index for first array element
fruits.push('Orange'); // add element to array (double check that don't have to assign to a new object)
remainingList = fruits.pop(); // remove from end (note remainingList is a new list? original list "fruits" stays the same? also note that pop() isn't returning the element that was removed!
or is MDN tutorial just confusing/mixed up??
</PRE>
<H5>Variable & scope</H5>
<PRE>
y = 1; // eg of undeclared variable, scope is global, even when first use is inside a function
var z = 2; // eg of delcared variable, if inside a function, not usable outside of fn it was declared. (aka constrained)
function can create new variable scoping, if block cannot.
</PRE>
<OL>
<LI>
var, let, const in ES6 (2015). Include explanation of hoisting:
<A HREF="https://www.digitalocean.com/community/tutorials/understanding-variables-scope-hoisting-in-javascript">Digital Ocean</A> <BR>
Note that duplication declaration with var is allowed (and no warnings!). <BR>
use `let` inside block or fn is recommended, reduce chance of overwritting global declaration. it also explicitly error out on duplicate `let` declaration
<LI>
additional diff b/w declared and undeclared vars:
(<A HREF="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var">MDN</A>)
<BR>
</OL>
<UL>
<LI> Declared variables are created before any code is executed. Undeclared variables do not exist until the code assigning to them is executed.
<LI> Declared variables are a non-configurable property of their execution context (function or global). Undeclared variables are configurable (e.g. can be deleted).
</UL>
<A ID="output"></A>
<H2>Quick Output</H2>
<PRE>
Quick output
- alert( "Hello World"); // this is a dialog pop up
- console.log("Hello Debugger"); // ^I in chrome opens debugger, go to console tab. (ctrl-sh-i)
- https://stackoverflow.com/questions/1208222/how-to-do-associative-array-hashing-in-javascript
- document.getElementById(id).innerHTML = "Hello Internet"; // id would be the id tag in a <div> etc.
</PRE>
<A ID="input"></A>
<H2>Input</H2>
<H5>Reading file from server</H5>
<UL>
<LI> <A HREF="https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Client-side_web_APIs/Fetching_data">https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Client-side_web_APIs/Fetching_data</A>
Reading file from server, but uses ajax, async method.
good for interactivity, painful for data analytics program :(
</UL>
<BR><HR><BR>
<H2>Refs/Links</H2>
<UL>
<LI><A HREF="script/javascript_eg.html">javascript_eg</A> (my own examples)</LI>
<LI><A HREF="script/javascript_date.html">javascript_date</A> (simple script print current date/time)</LI>
<LI><A HREF="https://tin6150.github.io/inet-dev-class/eg-code/eg-js.html">eg-code/eg-js</A>ajax eg, prob not working anymore</LI>
<LI></LI>
<LI><A HREF="https://github.com/tin6150/inet-dev-class/tree/master/mapbox">mapbox examples</A>. See Examples section, most have javascript in them.</LI>
<LI><A HREF="https://tin6150.github.io/inet-dev-class/mapbox/smelly_polyg.html">Smelly</A>Mapbox JS app for ETA collaboration about garbage/energy sites and odor dispersion simulation info</LI>
<LI><A HREF="https://tin6150.github.io/inet-dev-class/mapbox/ZWEDC_jq_slider.html">mapbox with jQuery slider</A>slider that i didn't end up using, but good example of jQuery usage with Mapbox GL JS</LI>
<LI></LI>
<LI><A HREF="https://tin6150.github.io/inet-dev-class/js/">inet-dev-class/js</A> (eg I tried before getting Mapbox GL JS working) ::</LI>
<LI><A HREF="https://tin6150.github.io/inet-dev-class/js/helloWorld.js">helloWorld.js</A>var, const, console.log()</LI>
<LI><A HREF="https://tin6150.github.io/inet-dev-class/js/mapFromFile.js">mapFromFile.js</A>(better to look at smelly above)</LI>
<LI><A HREF=""></A></LI>
<LI></LI>
<LI><A HREF="https://tin6150.github.io/inet-dev-class/jQuery/">jQuery</A>
(<A HREF="jquery_class/">alt loc in jquery_class</A>) :: </LI>
<LI><A HREF="https://tin6150.github.io/inet-dev-class/jQuery/main.html">jQuery class homework toc</A>(don't seems to be working after dropbox cut off html web hosting)</LI>
<LI><A HREF="https://tin6150.github.io/taxonomy_reporter/taxorpt_sample_output.html">taxonomy_reporter</A>data table jQuery for highlight, sectioning and sorting. yet html remains very clean for even text-based viewing.</LI>
<LI><A HREF=""></A></LI>
<LI></LI>
<LI><A HREF="https://tin6150.github.io/inet-dev-class/css/">css</A> :: </LI>
<LI><A HREF="https://tin6150.github.io/inet-dev-class/css/ho-embeded.html">ho-embeded.html</A> simple page with embeded css</LI>
<LI>See psg2.html/psg2.css for example used for the Pocked SysAdmin Guide pages, done after taking the css class.</LI>
<LI>psg2.html, psg1.html both have various javascript thing for g+, translate, and other stuff in it </LI>
<LI><A HREF=""></A></LI>
<LI></LI>
</UL>
<BR>
<A ID="validator"></A>
<H1>Validator</H1>
Old school HTML badge icon buttons :) <BR>
HTML validator: http://validator.w3.org/ <BR>
<!--(no more badge icon?)-->
<A HREF="https://validator.w3.org/check?uri=https%3A%2F%2Ftin6150.github.io%2Fpsg%2Fjavascript.html&charset=%28detect+automatically%29&doctype=HTML+2.0&group=0&user-agent=W3C_Validator%2F1.3+http%3A%2F%2Fvalidator.w3.org%2Fservices">(for this page)</A> <BR>
<BR>
(see simple.html for easier test first)
<BR>
Hmm for css... need new link from blue icon. <BR>
CSS validator:
<a href="http://jigsaw.w3.org/css-validator/">http://jigsaw.w3.org/css-validator/</A>
<BR>
<a href="http://jigsaw.w3.org/css-validator/check/referer">
<img style="border:0; width:88px; height:31px"
src="http://jigsaw.w3.org/css-validator/images/vcss"
alt="CSS validity icon" />
</a>
<-- This version said to work with HTML/XML, but don't seems to work no more for me.
<BR>
<a href="http://jigsaw.w3.org/css-validator/validator?uri=https%3A%2F%2Ftin6150.github.io%2Fpsg%2Fjavascript.html&profile=css3svg&usermedium=all&warning=1&vextwarning=">
<img style="border:0;width:88px;height:31px"
src="https://jigsaw.w3.org/css-validator/images/vcss-blue"
alt="Valid CSS!" />
</a>
<-- This version with embeded uri works
<BR><BR><HR>
<div align="CENTER">
[Doc URL: <A HREF="http://tin6150.github.io/psg/psg/javascript.html">
http://tin6150.github.io/psg/psg/javascript.html</A>]
<BR>
(cc) Tin Ho. See
<A HREF=psg.html#cc>main page</A>
for copyright info. <BR>
<HR>
<A HREF="http://www.taos.com"><IMG SRC="banner/taos_banner1.gif" width="728" height="98"></A>
</div>
<div class="sig"><BR>
hoti1<BR>
bofh1</div>
</body>
<!-- Google analytics new tracking code ga.js. Will actually need to add this code to every page for full tracking! (still the case in 2011?) Using my gmail login 2011.0617 updated with code for http://tin6150.github.io/psg/psg.html --> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-4515095-4']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script>
</html>