From b6c44658563baf921004857d51b94114703f5983 Mon Sep 17 00:00:00 2001
From: Garrett Johnson
Date: Sun, 5 Feb 2012 17:08:22 -0500
Subject: [PATCH 1/4] rearranged some wording, added some emphasis on the
importantence of understanding javascript
---
content/javascript-101/dex.md | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/content/javascript-101/dex.md b/content/javascript-101/dex.md
index 9ac27633..f2376b9f 100644
--- a/content/javascript-101/dex.md
+++ b/content/javascript-101/dex.md
@@ -5,9 +5,6 @@ section : 1
attribution: jQuery Fundamentals
---
-jQuery is built on top of JavaScript, a rich and expressive language in its own
-right. This section covers the basic concepts of JavaScript, as well as some
-frequent pitfalls for people who have not used JavaScript before. While it will
-be of particular value to people with no programming experience, even people
-who have used other programming languages may benefit from learning about some
-of the peculiarities of JavaScript.
+jQuery is built on top of JavaScript, a rich and expressive language in its own right. This means when using jQuery, we are still writing valid JavaScript; it just serves as a framework to make many aspects of writing JavaScript easier and more reliable in the various browser environments. With that said, a basic knowledge of JavaScript will go a long way in understanding, structuring, and debugging our code; jQuery will just help make that basic knowledge go much, much further.
+
+This section covers the basic concepts of JavaScript, as well as some frequent pitfalls many developers fall into during their first foray into the language. While it will be of particular value to people with little to no programming experience, even people who have used other programming languages may benefit from learning about some of the peculiarities of JavaScript.
\ No newline at end of file
From 1e6b75b40794adb496ea89fcb925506479e3501b Mon Sep 17 00:00:00 2001
From: Garrett Johnson
Date: Sun, 5 Feb 2012 21:13:15 -0500
Subject: [PATCH 2/4] new section on how to run code
---
content/javascript-101/running-code.md | 81 ++++++++++++++++++++++++++
1 file changed, 81 insertions(+)
create mode 100644 content/javascript-101/running-code.md
diff --git a/content/javascript-101/running-code.md b/content/javascript-101/running-code.md
new file mode 100644
index 00000000..36a03f13
--- /dev/null
+++ b/content/javascript-101/running-code.md
@@ -0,0 +1,81 @@
+---
+chapter: javascript-101
+section: 1
+title: Running Code
+attribution: jQuery Fundamentals
+github: jquery
+---
+
+### External
+
+The first and recommended option is to write our code in an external file (with a ".js" extension), which can then be included on our web page using a HTML script tag and pointing the "src" attribute to our file's location. Having our JavaScript in it's own file will reduce code duplication if we wish to reuse it on other pages and will allow the browser to cache the file on the remote client's computer, decreasing our page load time.
+
+
+alert('Hello World!');
+
+
+
+
+
+
+### Inline
+
+The second option is to inline the code directly on the web page. This is also achieved using HTML script tags but instead of pointing the "src" attribute to a file, we place the code between the tags. While there are use cases for this option, the majority of the time it is best to keep our code in an external file as described above.
+
+
+
+
+
+### Attributes
+
+The last and strongly discouraged option, is to utilize the event handler attributes of HTML attributes.
+
+
+Click Me!
+
+
+### Placement
+
+Placement of the previous two options is important and can vary depending on the situation. If we are including some JavaScript which does not access the elements on the page, we can safely place the script before the closing HTML head tag. However, if the code will interact with the elements on the page, we have to make sure those elements exists at the time of our script's execution. A common pitfall can be seen in the following example where we attempt to find the element with an ID of "hello-world", the problem here is our script will be executed prior to the element being defined within the document.
+
+
+
+
+
+
+
+
+
Hello World
+
+
+
+
+It is a common pattern to just move our scripts to the bottom of the page, prior to the closing HTML body tag. This will guarentee the defination of any element we may need when our script is executed.
+
+
+
+
+
+
+
+
Hello World
+
+
+
+
+
+
+
+
+
+
+
From ec302b7a68d0029b3bcdf8209a4d078a3de78301 Mon Sep 17 00:00:00 2001
From: Garrett Johnson
Date: Sun, 5 Feb 2012 21:14:37 -0500
Subject: [PATCH 3/4] new content and linked out to mdn for keywords
---
content/javascript-101/syntax-basics.md | 76 ++++++++++++++++++++-----
1 file changed, 63 insertions(+), 13 deletions(-)
diff --git a/content/javascript-101/syntax-basics.md b/content/javascript-101/syntax-basics.md
index f63203e2..a8cb571f 100644
--- a/content/javascript-101/syntax-basics.md
+++ b/content/javascript-101/syntax-basics.md
@@ -1,27 +1,77 @@
---
-chapter: js101
-section: 1
+chapter: javascript-101
+section: 2
title: Syntax Basics
attribution: jQuery Fundamentals
github: jquery
---
-Understanding statements, variable naming, whitespace, and other basic JavaScript syntax.
-
-var foo = 'hello world';
-
+### Comments
+
+JavaScript has support for single and multi line comments. Comments are ignored by the JavaScript engine, therefore have no side-effects on the outcome of the program. They should be used to document the code for future developers (including yourself!). There are libraries available that can generate project documentation pages based on commenting conventions used, [JSDoc](http://code.google.com/p/jsdoc-toolkit/, "JSDoc Toolkit") is one of the more popular ones.
+
+
+// this is an example of a single line comment.
-
-var foo = 'hello world';
+/*
+ * this is an example
+ * of a
+ * multi line
+ * comment.
+ */
-
-2 * 3 + 5; // returns 11; multiplication happens first
-2 * (3 + 5); // returns 16; addition happens first
+### Whitespace
+
+Whitespace is also ignored in JavaScript. There are many tools that will actully strip out all the whitespace in a program reducing the overall file size in order to improve network latency. Given the availability of tools like these, whitespace should be leveraged to make the code as readible as possible.
+
+
+var hello = "Hello";
+var world = "World!";
-
+
+// readible code is good!
var foo = function() {
- console.log('hello');
+ for (var i = 0; i < 10; i++) {
+ alert(i);
+ }
};
+
+foo();
+
+// not so much!
+var foo=function(){for(var i=0;i<10;++){alert(i);}};foo();
+
+
+### Reserved Words
+
+There is a handfull of reserved words that cannot be used when declaring user defined variables and functions. Some of these are currently implemented, some for future use, and others for historical reasons. A list of words and in depth explaination can be found on the [MDN JavaScript Reference](https://developer.mozilla.org/en/JavaScript/Reference/Reserved_Words, "MDN Reserved Words.")
+
+### Identifiers
+
+Identifiers are used to name variables and functions with a unique name so they can subsequently be refererred to by that name; variables and functions will be discussed in a later chapter. The name of an identifier must follow a few rules:
+
+* Cannot be a reserved word.
+* Can only be composed of letters, numbers, dollar signs, and underscores.
+* The first character cannot be a number.
+
+It is best practice to name these identifiers to something that will make sense to other developers and to you later on.
+
+
+var myAwesomeVariable = 'a';
+var myAwesomeVariable2 = 'b';
+var my_awesome_variable = 'c';
+var $my_AwesomeVariable = 'd';
+var _my_awesome_variable_$ = 'e';
+
+While it is possible to run JavaScript in server-side environments, that is out of the scope for this section.
+
+
+
+
+
+
+
+
From 267d07a7f74284f9d0ab240d42a1b32b76711119 Mon Sep 17 00:00:00 2001
From: Garrett Johnson
Date: Sun, 5 Feb 2012 21:19:51 -0500
Subject: [PATCH 4/4] new section on types, functions will get their own
section
---
content/javascript-101/types.md | 171 ++++++++++++++++++++++++++++++++
1 file changed, 171 insertions(+)
create mode 100644 content/javascript-101/types.md
diff --git a/content/javascript-101/types.md b/content/javascript-101/types.md
new file mode 100644
index 00000000..a989dd85
--- /dev/null
+++ b/content/javascript-101/types.md
@@ -0,0 +1,171 @@
+---
+chapter: javascript-101
+section: 2
+title: Types
+attribution: jQuery Fundamentals
+github: jquery
+---
+
+The types in JavaScript fall into two categories; primitives and objects. The primitive types include:
+
+* string
+* number
+* boolean
+* null
+* undefined
+
+### String
+
+String types are text wrapped in single or double quotation marks, but it is best practice to stick with a consistent variation. There may be times when the string contains quotation marks that collide with the ones used to create the string; in this case we must either escape the characters using a `\` backslash or use different quotes around the string.
+
+
+var a = "I am a string";
+var b = 'So am I!';
+
+alert(a);
+alert(b);
+
+
+
+var statement1 = 'He said "JavaScript is awesome!"';
+var statement2 = "He said \"JavaScript is awesome!\"";
+
+
+### Number
+
+Number types are just any positive or negative numeric value, there is no distinction between integer and floating point values.
+
+
+var num1 = 100;
+var num2 = 100.10;
+var num3 = 0.10;
+
+
+### Boolean
+Boolean types are just simply true or false.
+
+
+var okay = true;
+var fail = false;
+
+
+### Undefined and Null
+
+Undefined and null are special types in JavaScript. Null types are a value that represent the absence of a value, this is similar to many other programming languages. Undefined types represent a state in which no value has been assigned at all, you can achieve this type in two ways; by using the undefined keyword or by just not defining a value at all.
+
+
+var foo = null;
+
+var bar1 = undefined;
+var bar2;
+
+
+### Objects
+
+Everything else is in JavaScript is considered an Object. While there are [numerous built-in objects](https://developer.mozilla.org/en/JavaScript/Reference#Global_Objects, "MDN - Global Object Reference"), the ones we will focus on in this chapter are:
+
+* Object
+* Array
+* Function
+
+The simplist way to create an object is either through the Object constructor or the short hand syntax other wise known as an object literal. These simple objects are unordered key/value pairs; the key is formally known as a property and the value can be any valid JavaScript type, even another object. To create or access a property on an object, we use what is known as "dot notation" or "bracket notation".
+
+
+var person1 = new Object;
+
+person1.firstName = "John";
+person1.lastName = "Doe";
+
+alert(person1.firstName + " " + person1.lastName);
+
+var person2 = {
+ firstName: "Jane",
+ lastName: "Doe"
+};
+
+alert(person2.firstName + " " + person2.lastName);
+
+
+
+var people = {};
+
+people['person1'] = person1;
+people['person2'] = person2;
+
+alert(people['person1'].firstName);
+alert(people['person2'].firstName);
+
+
+What happens if a property is accessed which has not been *defined* yet? Well, it will be a type of undefined.
+
+
+var person = { name: "John Doe" };
+alert(person.email); // => undefined
+
+
+### Array
+
+Arrays are a type of object which are ordered by the index of each item that it contains; this index starts at zero and extends to however many items have been added, also known as the "length" of the array which happens to be a property as well. Similar to a basic object, an array can be created with the Array Constructor or the short hand syntax known as an array literal.
+
+
+var foo = new Array;
+var bar = [];
+
+
+There is an important distinction to be made between the two though. An array literal can contain items to be added to the array upon creating it, the same is possisble for the Array Constructor. However, if just a single numeric item is passed in, the Array Constructor will assume its length to be that value.
+
+
+var foo = [100];
+alert(foo[0]);
+alert(foo.length);
+
+var bar = new Array(100);
+alert(bar[0]);
+alert(bar.length);
+
+
+An array can be manipulated through the methods that are avaiable on the instance and items can be accessed using bracket notation with a given index, the value will be undefined if the index does not exists or contains no value.
+
+
+var foo = [];
+
+foo.push('a');
+foo.push('b');
+
+alert(foo[0]);
+alert(foo[1]);
+
+alert(foo.length);
+
+foo.pop();
+
+alert(foo[0]);
+alert(foo[1]);
+
+alert(foo.length);
+
+foo.unshift('z');
+
+alert(foo[0]);
+alert(foo[1]);
+
+alert(foo.length);
+
+foo.shift();
+
+alert(foo[0]);
+alert(foo[1]);
+
+alert(foo.length);
+
+
+There are many more methods for manipulating arrays, details can be found on the [MDN Document](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array "MDN - Array Reference")
+
+
+
+
+
+
+
+
+