summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKyle K <kylek389@gmail.com>2017-02-25 17:45:07 -0600
committerKyle K <kylek389@gmail.com>2017-02-25 17:45:07 -0600
commitb4062724b3e932e91a81e7db63732d6091e314a4 (patch)
tree52e4a53ca7c8fe6acfe3c87a14a441de2a9045fc
parented2b003ea059d7c6a62ee3e35bc3c6d3ce73da8b (diff)
downloadjsexamples-b4062724b3e932e91a81e7db63732d6091e314a4.tar.gz
jsexamples-b4062724b3e932e91a81e7db63732d6091e314a4.tar.bz2
jsexamples-b4062724b3e932e91a81e7db63732d6091e314a4.zip
js notes
-rw-r--r--jsnotes.txt60
1 files changed, 59 insertions, 1 deletions
diff --git a/jsnotes.txt b/jsnotes.txt
index d28e473..ea4a049 100644
--- a/jsnotes.txt
+++ b/jsnotes.txt
@@ -1,7 +1,27 @@
+JS...
+- JS includes keyval as language construct (aka associative array/hashtable/dictionary),
+ this brings confusion and multiple ways to do 1 thing (as objects, arrays, and functions can be interchangeable)
+- everything is an object, if that wasn't enough, JS is reflective,
+ at any point we may add/mutate properties of object e.g. foo.newmember = "bar";
+
+Best practices / rule of thumb
+- when in doubt how to store data, always start with JSON (don't sore functions)
+- always use 'var' keyword unless you're dereferencing a global
+
+Functions
+- all functions are objects
+- 'this' keyword can be used in function if it is being new'ed (as in creating object/instance),
+ if function was called without 'new' then this.foo will bind to window.foo ...
+- NEW keyword, JS expects a constructor when new'ing, this implies we should NEW a function,
+ new'ing e.g. 'new {} throws TypeError: object is not a function'
+
+
[references]
http://msdn.microsoft.com/en-us/library/ie/d1et7k7c%28v=vs.94%29.aspx
[data types]
+- built-ins?
+ the keval/dictionary/hash/associate-array language construct
- primitive
string, number boolean
@@ -15,6 +35,9 @@ http://msdn.microsoft.com/en-us/library/ie/d1et7k7c%28v=vs.94%29.aspx
null, undefined
note: null is not 0, does not have type, undefined is a string
+[scope]
+- var keyword is used to make local variables
+
[anonymous functions]
wrapping code inside of 'function() { code } ()' is handy for creating a
namespace for your code and restricting scope, since js essentially has
@@ -38,4 +61,39 @@ defined in
when function is assigned to this object, only 1 copy exists, it is memory
efficient, also we get expected behavior when overriding that function
- 'new' changes meaning of a function, upon invocation, function is ran in blank
- object context \ No newline at end of file
+ object context
+
+
+[some examples]
+> 4 - 2 is 2
+> 4 - "2" is 2
+> "4" + 2 is "42"
+
+> 0 == false true
+> 1 == "1" true (js
+> 1 === "1" false (no type coercion is taking place)
+
+> [] + [] "" empty string
+> [] + {} {object Object] Object
+> {} + [] 0
+> {} + {} NaN
+
+
+~~~~~----- BROWSER -----~~~~~
+
+[JS in a browser]
+- there are 3 main global objects
+ 1) window......is the execution context and global object for that context's JS
+ 2) document....contains the HTML
+ 3) screen......describes the physical display's full screen
+
+
+- your code gets executed inside something that looks like
+
+ with (window) {
+ //Your code
+ }
+
+- console.log is not available in to use from within HTML->JS, however it does exist in browser's console (Ctrl+Shift+k or F12)
+
+~~~~~----------~~~~~