Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Drjonees4729yWhat's the benefits of putting the var route; on top of the loop instead of for(var route...)?
PS. I'm a noobie ;) -
MarShal1329y@caroso1222 @Drjonees This really depends on the nature of the data in routes. From the looks of it, it seems like an object, so a for in loop makes sense if he is looping for keys in an object and obtaining their values. Foreach works for arrays only, and that can return both the value and index of the object. I hope this clears it up Drjonees
-
@MarShal you are totally right! :) I got confused with Angular's forEach which you can indeed use for iterating objects or arrays.
-
MarShal1329y@Drjonees In javascript there is no difference, its a personal preference. In other programing languages it can be used for accessing the variable outside the scope of the loop. In C, the variable MUST be declared outside the loop. So it depends on the programing language but in javascript its a personal preference and has no effect ;)
-
MarShal1329y@caroso1222 yeah versions of javascript frameworks have their own twists and turns to the language, which makes migrating from vanilla JavaScript to those frameworks more or less tricky. But hey, we all learn right, its all about the journey ;)
Related Rants
When you begin to feel like Hodor...
undefined
hodor
angular