Skip to content

Commit f32a974

Browse files
committed
converted 'Types' code to the new convention
1 parent 9938d89 commit f32a974

File tree

1 file changed

+40
-36
lines changed

1 file changed

+40
-36
lines changed

page/javascript-101/types.md

+40-36
Original file line numberDiff line numberDiff line change
@@ -16,47 +16,52 @@ The types in JavaScript fall into two categories; primitives and objects. The pr
1616

1717
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.
1818

19-
<javascript caption="Strings can created with double or single quotes.">
19+
``` js
20+
// Strings can created with double or single quotes.
2021
var a = "I am a string";
2122
var b = 'So am I!';
2223

2324
alert(a);
2425
alert(b);
25-
</javascript>
26+
```
2627

27-
<javascript caption="Sometimes a string may contain quotation marks.">
28+
``` js
29+
// Sometimes a string may contain quotation marks.
2830
var statement1 = 'He said "JavaScript is awesome!"';
2931
var statement2 = "He said \"JavaScript is awesome!\"";
30-
</javascript>
32+
```
3133

3234
### Number
3335

3436
Number types are just any positive or negative numeric value, there is no distinction between integer and floating point values.
3537

36-
<javascript caption="Numbers are any whole or floating point integer.">
38+
``` js
39+
// Numbers are any whole or floating point integer.
3740
var num1 = 100;
3841
var num2 = 100.10;
3942
var num3 = 0.10;
40-
</javascript>
43+
```
4144

4245
### Boolean
4346
Boolean types are just simply true or false.
4447

45-
<javascript caption="Boolean values.">
48+
``` js
49+
// Boolean values.
4650
var okay = true;
4751
var fail = false;
48-
</javascript>
52+
```
4953

5054
### Undefined and Null
5155

5256
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.
5357

54-
<javascript caption="Two ways to acheive an undefined value.">
58+
``` js
59+
\\ Two ways to achieve an undefined value.
5560
var foo = null;
5661

5762
var bar1 = undefined;
5863
var bar2;
59-
</javascript>
64+
```
6065

6166
### Objects
6267

@@ -66,9 +71,10 @@ Everything else is in JavaScript is considered an Object. While there are [numer
6671
* Array
6772
* Function
6873

69-
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".
74+
The simplest 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".
7075

71-
<javascript caption="Simple objects using the constructor or the literal syntax.">
76+
``` js
77+
// Simple objects using the constructor or the literal syntax.
7278
var person1 = new Object;
7379

7480
person1.firstName = "John";
@@ -82,49 +88,53 @@ var person2 = {
8288
};
8389

8490
alert(person2.firstName + " " + person2.lastName);
85-
</javascript>
91+
```
8692

87-
<javascript caption="As mentioned, objects can also have objects as a property.">
93+
``` js
94+
// As mentioned, objects can also have objects as a property.
8895
var people = {};
8996

9097
people['person1'] = person1;
9198
people['person2'] = person2;
9299

93100
alert(people['person1'].firstName);
94101
alert(people['person2'].firstName);
95-
</javascript>
102+
```
96103

97104
What happens if a property is accessed which has not been *defined* yet? Well, it will be a type of undefined.
98105

99-
<javascript caption="Properties that have not been created are undefined.">
106+
``` js
107+
// Properties that have not been created are undefined.
100108
var person = { name: "John Doe" };
101109
alert(person.email); // => undefined
102-
</javascript>
110+
```
103111

104112
### Array
105113

106114
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.
107115

108-
<javascript caption="Creating an array with initial items">
116+
``` js
117+
// Creating an array with initial items
109118
var foo = new Array;
110119
var bar = [];
111-
</javascript>
120+
```
112121

113-
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.
122+
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 possible 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.
114123

115-
<javascript caption="">
124+
``` js
116125
var foo = [100];
117126
alert(foo[0]);
118127
alert(foo.length);
119128

120129
var bar = new Array(100);
121130
alert(bar[0]);
122131
alert(bar.length);
123-
</javascript>
132+
```
124133

125-
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.
134+
An array can be manipulated through the methods that are available 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.
126135

127-
<javascript caption="Using the push(), pop(), unshift() and shift() methods.">
136+
``` js
137+
// Using the push(), pop(), unshift() and shift() methods.
128138
var foo = [];
129139

130140
foo.push('a');
@@ -155,7 +165,7 @@ alert(foo[0]);
155165
alert(foo[1]);
156166

157167
alert(foo.length);
158-
</javascript>
168+
```
159169

160170
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")
161171

@@ -164,10 +174,11 @@ There are many more methods for manipulating arrays, details can be found on the
164174
jQuery offers a few basic utility methods for determining the type of a
165175
specific value.
166176

167-
<javascript caption="Checking the type of an arbitrary value">
177+
``` js
178+
// Checking the type of an arbitrary value
168179
var myValue = [1, 2, 3];
169180

170-
// Using JavaScript's typeof operator to test for primative types
181+
// Using JavaScript's typeof operator to test for primitive types
171182
typeof myValue == 'string'; // false
172183
typeof myValue == 'number'; // false
173184
typeof myValue == 'undefined'; // false
@@ -176,15 +187,8 @@ typeof myValue == 'boolean'; // false
176187
// Using strict equality operator to check for null
177188
myValue === null; // false
178189

179-
// Using jQuery's methods to check for non-primative types
190+
// Using jQuery's methods to check for non-primitive types
180191
jQuery.isFunction(myValue); // false
181192
jQuery.isPlainObject(myValue); // false
182193
jQuery.isArray(myValue); // true
183-
</javascript>
184-
185-
186-
187-
188-
189-
190-
194+
```

0 commit comments

Comments
 (0)