Skip to content

Commit 6e0db70

Browse files
Markus Amalthea Magnusonajpiano
Markus Amalthea Magnuson
authored andcommitted
Style and typography fixes, and code style adherence in the JavaScript 101 section. Fixes jquery#312.
1 parent ddb475e commit 6e0db70

15 files changed

+411
-497
lines changed

page/javascript-101.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
title : JavaScript 101
33
level: beginner
44
source: http://jqfundamentals.com/legacy
5-
attribution:
5+
attribution:
66
- jQuery Fundamentals
77
customFields:
88
-
99
key: "icon"
1010
value: "pencil"
1111
---
1212

13-
##Introduction
13+
## Introduction
14+
1415
So you want to unlock the power of jQuery to make the web a better place? Awesome, but there are a few things you should know about JavaScript first.
1516

1617
Introduced at the dawn of the web, [JavaScript](http://en.wikipedia.org/wiki/JavaScript) is a powerful and expressive language that runs inside the browser in conjunction with HTML and CSS. Based on an open standard called [ECMAScript](http://en.wikipedia.org/wiki/ECMAScript), JavaScript has quickly become the "programming language of the web". All the power of jQuery is accessed via JavaScript, so needless to say, it's an important language to learn. Having a basic knowledge of JavaScript will go a long way in understanding, structuring and debugging your code.

page/javascript-101/arrays.md

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,39 @@
22
title: Arrays
33
level: beginner
44
source: http://jqfundamentals.com/legacy
5-
attribution:
5+
attribution:
66
- jQuery Fundamentals
77
---
88
Arrays are zero-indexed, ordered lists of values. They are a handy way to store a set of related items of the same type (such as strings), though in reality, an array can include multiple types of items, including other arrays.
99

1010
To create an array, either use the object constructor or the literal declaration, by assigning the variable a list of values after the declaration.
1111

1212
```
13-
// A simple array with constructor
14-
var myArray1 = new Array( "hello", "world" );
15-
// literal declaration, the preferred way
16-
var myArray2 = [ "hello", "world" ];
13+
// A simple array with constructor.
14+
var myArray1 = new Array( "hello", "world" );
15+
// Literal declaration, the preferred way.
16+
var myArray2 = [ "hello", "world" ];
1717
```
1818

1919
The literal declaration is generally preferred. See the [Google Coding Guidelines](http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml#Array_and_Object_literals) for more information.
2020

21-
If the values are unknown, it is also possible to declare an empty Array, and add elements either through functions or through accessing by index:
21+
If the values are unknown, it is also possible to declare an empty array, and add elements either through functions or through accessing by index:
2222

2323
```
2424
// Creating empty arrays and adding values
2525
var myArray = [];
2626
2727
// adds "hello" on index 0
28-
myArray.push("hello");
28+
myArray.push( "hello" );
2929
3030
// adds "world" on index 1
31-
myArray.push("world");
31+
myArray.push( "world" );
3232
3333
// adds "!" on index 2
3434
myArray[ 2 ] = "!";
3535
```
3636

37-
'push' is a function that adds an element on the end of the array and expands the array respectively. You also can directly add items by index. Missing indices will be filled with 'undefined'.
37+
`.push()` is a function that adds an element on the end of the array and expands the array respectively. You also can directly add items by index. Missing indices will be filled with `undefined`.
3838

3939
```
4040
// Leaving indices
@@ -47,7 +47,7 @@ myArray[ 3 ] = "!";
4747
console.log( myArray ); // [ "hello", "world", undefined, "!" ];
4848
```
4949

50-
If the size of the array is unknown, 'push' is far more safe. You can both access and assign values to array items with the index.
50+
If the size of the array is unknown, `.push()` is far more safe. You can both access and assign values to array items with the index.
5151

5252
```
5353
// Accessing array items by index
@@ -58,7 +58,7 @@ console.log( myArray[2] ); // "!"
5858

5959
## Array Methods and Properties
6060

61-
### `.length`
61+
### .length
6262

6363
The `.length` property is used to determine the amount of items in an array.
6464

@@ -76,7 +76,7 @@ You will need the `.length` property for looping through an array:
7676
var myArray = [ "hello", "world", "!" ];
7777
7878
for ( var i = 0; i < myArray.length; i = i + 1 ) {
79-
console.log( myArray[i] );
79+
console.log( myArray[i] );
8080
}
8181
```
8282

@@ -87,13 +87,13 @@ Except when using `for`/`in` loops:
8787
var myArray = [ "hello", "world", "!" ];
8888
8989
for ( var i in myArray ) {
90-
console.log( myArray[ i ] );
90+
console.log( myArray[ i ] );
9191
}
9292
```
9393

94-
### `.concat`
94+
### .concat()
9595

96-
Concatenate two or more arrays with `.concat`:
96+
Concatenate two or more arrays with `.concat()`:
9797

9898
```
9999
// Concatenating Arrays
@@ -104,9 +104,9 @@ var myOtherArray = [ 5, 6, 7 ];
104104
var wholeArray = myArray.concat( myOtherArray );
105105
```
106106

107-
### `.join`
107+
### .join()
108108

109-
`.join` creates a string representation of an array by joining all of its elements using a separator string. If no separator is supplied (e.g. `.join` is called without arguments) the array will be joined using a comma:
109+
`.join()` creates a string representation of an array by joining all of its elements using a separator string. If no separator is supplied (e.g. `.join()` is called without arguments) the array will be joined using a comma:
110110

111111
```
112112
// Joining elements
@@ -124,9 +124,9 @@ console.log( myArray.join("") ); // "helloworld!"
124124
125125
```
126126

127-
### `.pop`
127+
### .pop()
128128

129-
`.pop` removes the last element of an array. It is the opposite method of `.push`:
129+
`.pop()` removes the last element of an array. It is the opposite method of `.push()`:
130130

131131
```
132132
// pushing and popping
@@ -138,7 +138,7 @@ myArray.push( 7 ); // [ 0 , 2 , 7 ]
138138
myArray.pop(); // [ 0 , 2 ]
139139
```
140140

141-
### `.reverse`
141+
### .reverse()
142142

143143
As the name suggests, the elements of the array are in reverse order after calling this method:
144144

@@ -150,9 +150,9 @@ var myArray = [ "world" , "hello" ];
150150
myArray.reverse();
151151
```
152152

153-
### `.shift`
153+
### .shift()
154154

155-
Removes the first element of an array. With `.push` and `.shift`, you can recreate the method of a [queue](http://en.wikipedia.org/wiki/Queue_(data_structure)):
155+
Removes the first element of an array. With `.push()` and `.shift()`, you can recreate the method of a [queue](http://en.wikipedia.org/wiki/Queue_(data_structure)):
156156

157157
```
158158
// queue with shift() and push()
@@ -164,7 +164,7 @@ myArray.push( 7 ); // [ 0 , 2 , 7 ]
164164
myArray.shift(); // [ 2 , 7 ]
165165
```
166166

167-
### `.slice`
167+
### .slice()
168168

169169
Extracts a part of the array and returns that part in a new array. This method takes one parameter, which is the starting index:
170170

@@ -177,9 +177,9 @@ console.log( myArray ); // [ 1, 2, 3, 4, 5, 6, 7, 8 ]
177177
console.log( newArray ); // [ 4, 5, 6, 7, 8 ]
178178
```
179179

180-
### `.splice`
180+
### .splice()
181181

182-
Removes a certain amount of elements and adds new ones at the given index. It takes at least 3 parameters:
182+
Removes a certain amount of elements and adds new ones at the given index. It takes at least three parameters:
183183

184184
```
185185
// splice method
@@ -200,7 +200,7 @@ myArray.splice( 1, 2, 1, 2, 3, 4 );
200200
console.log( myArray ); // [ 0, 1, 2, 3, 4, 5 ]
201201
```
202202

203-
### `.sort`
203+
### .sort()
204204

205205
Sorts an array. It takes one parameter, which is a comparing function. If this function is not given, the array is sorted ascending:
206206

@@ -214,7 +214,7 @@ myArray.sort(); // 1, 3, 4, 6
214214
```
215215
// sorting with comparing function
216216
function descending( a, b ) {
217-
return b - a;
217+
return b - a;
218218
}
219219
220220
var myArray = [ 3, 4, 6, 1 ];
@@ -224,7 +224,7 @@ myArray.sort( descending ); // [ 6, 4, 3, 1 ]
224224

225225
The return value of descending (for this example) is important. If the return value is less than zero, the index of a is before b, and if it is greater than zero it's vice-versa. If the return value is zero, the elements index is equal.
226226

227-
### `.unshift`
227+
### .unshift()
228228

229229
Inserts an element at the first position of the array:
230230

@@ -237,29 +237,30 @@ myArray.unshift( 2 ); // [ 2 , 0 ]
237237
myArray.unshift( 7 ); // [ 7 , 2 , 0 ]
238238
```
239239

240-
### `.forEach`
240+
### .forEach()
241241

242-
In modern browsers it is possible to traverse through arrays with a `.forEach` method, where you pass a function that is called for each element in the array.
242+
In modern browsers it is possible to traverse through arrays with a `.forEach()` method, where you pass a function that is called for each element in the array.
243243

244244
The function takes up to three arguments:
245+
245246
* *Element* - The element itself.
246247
* *Index* - The index of this element in the array.
247248
* *Array* - The array itself.
248249

249-
All of these are optional, but you will need at least the 'element' parameter in most cases.
250+
All of these are optional, but you will need at least the "Element" parameter in most cases.
250251

251252
```
252253
// native forEach
253254
function printElement( elem ) {
254-
console.log( elem );
255+
console.log( elem );
255256
}
256257
257258
function printElementAndIndex( elem, index ) {
258-
console.log( "Index " + index + ": " + elem );
259+
console.log( "Index " + index + ": " + elem );
259260
}
260261
261262
function negateElement( elem, index, array ) {
262-
array[ index ] = -elem;
263+
array[ index ] = -elem;
263264
}
264265
265266
myArray = [ 1, 2, 3, 4, 5 ];

0 commit comments

Comments
 (0)