42
Nesqwik
8y

When you begin to feel like Hodor...

Comments
  • 0
    Route route ! :')
  • 1
    Hahaha Gold! πŸ˜‚
    Good luck to whoever would like to understand it later πŸ˜‚
  • 0
    What's the benefits of putting the var route; on top of the loop instead of for(var route...)?
    PS. I'm a noobie ;)
  • 1
    @Drjonees I think I wouldve been better to use the built in forEach()
  • 0
  • 1
    @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
  • 0
    @MarShal oh yea okay. Ty. But why have var route; outside of the loop?
  • 1
    @MarShal you are totally right! :) I got confused with Angular's forEach which you can indeed use for iterating objects or arrays.
  • 1
    @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 ;)
  • 0
    @MarShal thank you. Then I understood it correctly. :D
  • 2
    @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 ;)
  • 1
    @Drjonees yup for sure ;)
Add Comment