Better JavaScript code