As others have said, we need more code to know for sure, but given the subject line, "variable scope in for loops" and the fact that you're using node, there's a decent chance that you're running into the gotcha described in the MDN article on Closures: Creating closures in loops: A common mistake <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures#Creating_closures_in_loops.3A_A_common_mistake>. The idea being that if you have an asynchronous call inside your switch that takes a function, that function will be run later, after both of the outer for loops are done iterating, so both "protocol" and "item" will always be on the last item.
Javascript scopes variables at the function level, so even though you can declare variables inside for statements, javascript "hoists" the variable declaration to the top of the function it is contained in. -- Job board: http://jobs.nodejs.org/ New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscr...@googlegroups.com. To post to this group, send email to nodejs@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/19deef3b-1e73-4f3c-bd94-79f7434bf7fc%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.