Hi all,
I’m working on the random quote generator project, and I’m trying to do it with vanilla JavaScript (i.e., no JQuery). Here is what the documentation says for a simple HTTP request:
<button id="ajaxButton" type="button">Make a request</button>
<script>
(function() {
var httpRequest;
document.getElementById("ajaxButton").addEventListener('click', makeRequest);
function makeRequest() {
httpRequest = new XMLHttpRequest();
if (!httpRequest) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
httpRequest.onreadystatechange = alertContents;
httpRequest.open('GET', 'test.html');
httpRequest.send();
}
function alertContents() {
if (httpRequest.readyState === XMLHttpRequest.DONE) {
if (httpRequest.status === 200) {
alert(httpRequest.responseText);
} else {
alert('There was a problem with the request.');
}
}
}
})();
</script>
Why does the code include the following:
if (!httpRequest) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
More specifically, what role is !httpRequest playing?