Getting Around Flashcards

Common programming concepts

1
Q

When can a “For” loop be used?

Advantages?

A

Technique for Array iteration

+ uses iteration variable instead of accessing every property on every loop

+ Iteration var can be declared within the loop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

When is a ‘For … in’ loop used?
How does it work?
Important efficiency tip?

A

Technique for enumeration of properties in objects (non-arrays)

  • accesses every property of the object
  • Test with object.hasOwnProperty( ) to skip prototype properties
for (var i in myThing) {
		if(myThing.hasOwnProperty(i){
			//loop stuff
		}
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly