Skip to content

Commit ee96e5e

Browse files
Markus Amalthea Magnusonajpiano
Markus Amalthea Magnuson
authored andcommitted
Various small fixes on the JavaScript 101 Types page. Fixes jquery#348.
1 parent 2e11643 commit ee96e5e

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

page/javascript-101/types.md

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ attribution:
66
- jQuery Fundamentals
77
---
88

9-
Types in JavaScript fall into two categories: primitives or objects. Primitive types include:
9+
Types in JavaScript fall into two categories: primitives and objects. Primitive types include:
1010

1111
* String
1212
* Number
@@ -67,13 +67,13 @@ var bar2;
6767

6868
## Objects
6969

70-
Everything else 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"), this chapter will cover:
70+
Everything else 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"), this chapter will cover:
7171

7272
* Object
7373
* Array
7474
* Function
7575

76-
The simplest way to create an object is either through the Object constructor or the shorthand syntax known as 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."
76+
The simplest way to create an object is either through the `Object` constructor or the shorthand syntax known as 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."
7777

7878
```
7979
// Creating an object with the constructor:
@@ -109,14 +109,14 @@ If a property is accessed that has not been defined, it will return a type of `u
109109
```
110110
// Properties that have not been created are undefined.
111111
var person = { name: "John Doe" };
112-
alert( person.email ); // => undefined
112+
alert( person.email ); // undefined
113113
```
114114

115115
Objects are covered further in the [Objects](/objects/) section.
116116

117117
### Array
118118

119-
Arrays are a type of object that are ordered by the index of each item it contains. The index starts at zero and extends to however many items have been added, which is a property of the array known as the `length` of the array. Similar to a basic object, an array can be created with the array constructor or the shorthand syntax known as array literal.
119+
An array is a type of object that is ordered by the index of each item it contains. The index starts at zero and extends to however many items have been added, which is a property of the array known as the `.length`. Similar to a basic object, an array can be created with the `Array` constructor or the shorthand syntax known as array literal.
120120

121121
```
122122
// Creating an array with the constructor:
@@ -131,51 +131,52 @@ There is an important distinction to be made between the two. Both an array cons
131131
```
132132
// The array literal returns a foo.length value of 1:
133133
var foo = [ 100 ];
134-
alert( foo[0] ); // => 100
135-
alert( foo.length ); // => 1
134+
alert( foo[ 0 ] ); // 100
135+
alert( foo.length ); // 1
136136
137137
// The array constructor returns a bar.length value of 100:
138138
var bar = new Array( 100 );
139-
alert( bar[0] ); // => undefined
140-
alert( bar.length ); // => 100
139+
alert( bar[ 0 ] ); // undefined
140+
alert( bar.length ); // 100
141141
```
142142

143143
An array can be manipulated through methods that are available on the instance of the array. Items in the array can be accessed using bracket notation with a given index. If the index does not exist or contains no value, the return type will be `undefined`.
144144

145145
A few common array methods are shown below:
146146

147147
```
148-
// Using the push(), pop(), unshift() and shift() methods on an array
148+
// Using the push(), pop(), unshift() and shift() methods on an array.
149+
149150
var foo = [];
150151
151152
foo.push( "a" );
152153
foo.push( "b" );
153154
154-
alert( foo[ 0 ] ); // => a
155-
alert( foo[ 1 ] ); // => b
155+
alert( foo[ 0 ] ); // a
156+
alert( foo[ 1 ] ); // b
156157
157-
alert( foo.length ); // => 2
158+
alert( foo.length ); // 2
158159
159160
foo.pop();
160161
161-
alert( foo[ 0 ] ); // => a
162-
alert( foo[ 1 ] ); // => undefined
162+
alert( foo[ 0 ] ); // a
163+
alert( foo[ 1 ] ); // undefined
163164
164-
alert( foo.length ); // => 1
165+
alert( foo.length ); // 1
165166
166167
foo.unshift( "z" );
167168
168-
alert( foo[ 0 ] ); => z
169-
alert( foo[ 1 ] ); => a
169+
alert( foo[ 0 ] ); // z
170+
alert( foo[ 1 ] ); // a
170171
171-
alert( foo.length ); => 2
172+
alert( foo.length ); // 2
172173
173174
foo.shift();
174175
175-
alert( foo[ 0 ] ); // => a
176-
alert( foo[ 1 ] ); // => undefined
176+
alert( foo[ 0 ] ); // a
177+
alert( foo[ 1 ] ); // undefined
177178
178-
alert( foo.length ); // => 1
179+
alert( foo.length ); // 1
179180
```
180181

181182
There are many more methods for manipulating arrays, some of which are covered further in the [Arrays](/arrays/) section. Details can be found on the [Mozilla Developer Network](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array "MDN - Array Reference").
@@ -185,22 +186,20 @@ There are many more methods for manipulating arrays, some of which are covered f
185186
jQuery offers a few basic utility methods for determining the type of a specific value. Type checking is covered further in the [Testing Type](/testing-type/) section, but here are some examples:
186187

187188
```
188-
// Checking the type of an arbitrary value
189+
// Checking the type of an arbitrary value.
190+
189191
var myValue = [ 1, 2, 3 ];
190192
191193
// Using JavaScript's typeof operator to test for primitive types:
192-
193194
typeof myValue === "string"; // false
194195
typeof myValue === "number"; // false
195196
typeof myValue === "undefined"; // false
196197
typeof myValue === "boolean"; // false
197198
198-
// Using strict equality operator to check for null
199-
199+
// Using strict equality operator to check for null:
200200
myValue === null; // false
201201
202-
// Using jQuery's methods to check for non-primitive types
203-
202+
// Using jQuery's methods to check for non-primitive types:
204203
jQuery.isFunction( myValue ); // false
205204
jQuery.isPlainObject( myValue ); // false
206205
jQuery.isArray( myValue ); // true

0 commit comments

Comments
 (0)