Tag loop comparison in JavaScript