How Nested For Loop Works In Javascript