Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript AJAX Basics (retiring) Programming AJAX Parsing JSON Data

Andrew Youngwerth
Andrew Youngwerth
10,188 Points

Is there a reason onreadystatechange doesn't follow the camelCase convention?

For example:

var xhr = new XMLHttpRequest();

xhr.onreadystatechange = function () {
      if (xhr.readyState === 4) {
          document.getElementById('ajax').innerHTML = xhr.responseText;
      }
};

notice xhr.onreadystatechange is not camelCased but xhr.responseText is. Is there a reason for this that I've missed?

1 Answer

A lot of the javascript events don't follow the camel case conventions (onclick, onmouseover, ...). So I guess the rule of thumb is that your methods should be camel case, but don't always expect events to follow suit because many were created before casing conventions became uniform.

Andrew Youngwerth
Andrew Youngwerth
10,188 Points

Thanks! It hadn't even occurred to me that those events didn't follow camelCase.