summaryrefslogtreecommitdiffhomepage
path: root/javascript.html.markdown
diff options
context:
space:
mode:
authorzlarsen <zlarsen@dmail.dixie.edu>2015-10-09 14:07:44 -0600
committerzlarsen <zlarsen@dmail.dixie.edu>2015-10-09 14:07:44 -0600
commit46b746e8c6101f8a25ba463fb2fb4045c29098a1 (patch)
tree688ca286a0ecb9590562504a53fde96c8bbfcd76 /javascript.html.markdown
parent0d0c495c701acc77047df138e169e7cc7ece5f97 (diff)
parentef40704f9b66ae85d7a8a6853abbbf8810af3b90 (diff)
Merge remote-tracking branch 'adambard/master' into forth-es
Diffstat (limited to 'javascript.html.markdown')
-rw-r--r--javascript.html.markdown20
1 files changed, 20 insertions, 0 deletions
diff --git a/javascript.html.markdown b/javascript.html.markdown
index 754832f1..6ea0b0bb 100644
--- a/javascript.html.markdown
+++ b/javascript.html.markdown
@@ -218,6 +218,26 @@ for (var i = 0; i < 5; i++){
// will run 5 times
}
+//The For/In statement loops iterates over every property across the entire prototype chain
+var description = "";
+var person = {fname:"Paul", lname:"Ken", age:18};
+for (var x in person){
+ description += person[x] + " ";
+}
+
+//If only want to consider properties attached to the object itself,
+//and not its prototypes use hasOwnProperty() check
+var description = "";
+var person = {fname:"Paul", lname:"Ken", age:18};
+for (var x in person){
+ if (person.hasOwnProperty(x)){
+ description += person[x] + " ";
+ }
+}
+
+//for/in should not be used to iterate over an Array where the index order is important.
+//There is no guarantee that for/in will return the indexes in any particular order
+
// && is logical and, || is logical or
if (house.size == "big" && house.colour == "blue"){
house.contains = "bear";