You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: page/javascript-101.md
+3-2Lines changed: 3 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -2,15 +2,16 @@
2
2
title : JavaScript 101
3
3
level: beginner
4
4
source: http://jqfundamentals.com/legacy
5
-
attribution:
5
+
attribution:
6
6
- jQuery Fundamentals
7
7
customFields:
8
8
-
9
9
key: "icon"
10
10
value: "pencil"
11
11
---
12
12
13
-
##Introduction
13
+
## Introduction
14
+
14
15
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.
15
16
16
17
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.
Copy file name to clipboardExpand all lines: page/javascript-101/arrays.md
+35-34Lines changed: 35 additions & 34 deletions
Original file line number
Diff line number
Diff line change
@@ -2,39 +2,39 @@
2
2
title: Arrays
3
3
level: beginner
4
4
source: http://jqfundamentals.com/legacy
5
-
attribution:
5
+
attribution:
6
6
- jQuery Fundamentals
7
7
---
8
8
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.
9
9
10
10
To create an array, either use the object constructor or the literal declaration, by assigning the variable a list of values after the declaration.
11
11
12
12
```
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" ];
17
17
```
18
18
19
19
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.
20
20
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:
22
22
23
23
```
24
24
// Creating empty arrays and adding values
25
25
var myArray = [];
26
26
27
27
// adds "hello" on index 0
28
-
myArray.push("hello");
28
+
myArray.push("hello");
29
29
30
30
// adds "world" on index 1
31
-
myArray.push("world");
31
+
myArray.push("world");
32
32
33
33
// adds "!" on index 2
34
34
myArray[ 2 ] = "!";
35
35
```
36
36
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`.
`.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:
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)):
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.
226
226
227
-
### `.unshift`
227
+
### .unshift()
228
228
229
229
Inserts an element at the first position of the array:
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.
243
243
244
244
The function takes up to three arguments:
245
+
245
246
**Element* - The element itself.
246
247
**Index* - The index of this element in the array.
247
248
**Array* - The array itself.
248
249
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.
0 commit comments