Why does this JavaScript work in