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

onReadyStateChange vs readyStateChange? What is the difference?

I am currently looking a the documentation for the onReadtSate change property. https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/onreadystatechange

Is the onReadyStateChange a property that manages the readystatechange event for the XMLHttpRequest Object?

It says in the documentation:

onreadystatechange property contains the event handler (function) to be called when the readystatechange event is fired.

Thank you very much!

2 Answers

Steven Parker
Steven Parker
243,200 Points

As the documentation says, "onReadyStateChange" contains a reference to the function that will be called when the associated event occurs. And "ReadyStateChange" is the name of that event (it's not a variable).

The description might make more sense when you look at some sample code. You'll see it gets assigned with either the name of a function, or assigned to an anonymous function that is defined at the same time.

Thank you for your reply. So if I understand, readyStateChange is an event that happens in the DOM when the stateChange changes?

Steven Parker
Steven Parker
243,200 Points

I would say readyStateChange is an event that happens in the DOM when the readyState changes.

Great, perfect! thank you so much!