diff --git a/page/javascript-101/objects.md b/page/javascript-101/objects.md index a619920d..1443fd18 100644 --- a/page/javascript-101/objects.md +++ b/page/javascript-101/objects.md @@ -7,6 +7,14 @@ attribution: --- Objects contain one or more key-value pairs. The key portion can be any string. The value portion can be any type of value: a number, a string, an array, a function, or even another object. When one of these values is a function, it’s called a method of the object. Otherwise, they are called properties. +In comparison to other programming languages objects in JavaScript are similar to: + +* Dictionaries in Python. +* Hashes in Perl and Ruby. +* Hash tables in C and C++. +* HashMaps in Java. +* Associative arrays in PHP. + As it turns out, nearly everything in JavaScript is an object — arrays, functions, numbers, even strings — and they all have properties and methods. ``` @@ -28,8 +36,28 @@ When creating object literals, note that the key portion of each key-value pair ``` // test var myObject = { - validIdentifier: 123, - "some string": 456, - 99999: 789 + validIdentifier: 123, + "some string": 456, + 99999: 789 }; ``` + +## Iterating Over the Enumerable Properties of an Object: + +``` +var myObject = { + validIdentifier: 123, + "some string": 456, + 99999: 789 +}; + +for ( var prop in myObject ) { + console.log( "Property : " + prop + " ; value : " + myObject[ prop ] ); +} + +// Would log : +// Property : 99999 ; value : 789 +// Property : validIdentifier ; value : 123 +// Property : some string ; value : 456 + +``` diff --git a/page/javascript-101/testing-type.md b/page/javascript-101/testing-type.md index 088fa6a9..de67f679 100644 --- a/page/javascript-101/testing-type.md +++ b/page/javascript-101/testing-type.md @@ -28,6 +28,8 @@ typeof myArray; // "object" -- Careful! typeof myString; // "string" typeof myNumber; // "number" typeof null; // "object" -- Careful! +typeof undefined; // "undefined" -- Careful! + if ( myArray.push && myArray.slice && myArray.join ) {