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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Ekramy M.Ali](https://uploads.teamtreehouse.com/production/profile-photos/4604132/micro_ekramy2020.jpg)
Ekramy M.Ali
17,748 Pointswhy request.readyState === 4 ? why 4 ?
I don't understand why using the number 4 exactily.
2 Answers
![Rabin Gharti Magar](https://uploads.teamtreehouse.com/production/profile-photos/11512886/micro_edit-LEA151221C3562.jpg)
Rabin Gharti Magar
Front End Web Development Techdegree Graduate 20,928 PointsHey Ekramy M.Ali,
4 is one of the value for the readyState property
. The full list of readyState values is:
0 - The request is initialized
1 - The request has been set up
2 - The request has been sent
3 - The request is in process
4 - The request is completed
if( xhr.readyState === 4 ) {
// Run this code
}
The above conditional statement checks, if the value is 4 which means if the request is complete, run the block of code. We can use other values (numbers) too but it will come up as incomplete or get an error whilst processing therefore we rarely use other numbers.
To learn more about this property and how it works, check out this stackoverflow: https://stackoverflow.com/questions/30522565/what-is-meaning-of-xhr-readystate-4
Check out this MDN, great resource: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/readyState
Hope this helps!
![Laura Dangler](https://secure.gravatar.com/avatar/6cbefc65cd59bb7312b82ef863990bb5?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Laura Dangler
3,301 PointsWhy didn't Dave give us this information. Seems kind of miss informed on that info. Thanks
Ekramy M.Ali
17,748 PointsEkramy M.Ali
17,748 PointsThank you Rabin Gharti Magar for your great explanation :)
Hanane Ladj
Front End Web Development Techdegree Graduate 15,686 PointsHanane Ladj
Front End Web Development Techdegree Graduate 15,686 PointsI was looking for this answer thanks Rabin Gharti Magar that makes sense.