I have tried below two javascript functions in chrome via developer tool however I thought second function would be invoked when js interpreter reaches it but didn't. Not sure why.
var x = function() { console.log("probably not invoked."); }
var x = function() { console.log("probably invoked."); };
x(); // I had to do this to invoke the function
The reason behind of testing this is I was using XmlHttpRequest first time while reading property name status of the object I ran into a piece of code as below I was told that onreadystatechange function pointer will be executed so I thought having semicolon on anonymous function would be executed when js interpreter reaches it?
function makeRequest() {
.....
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
document.getElementById("status").innerHTML = (xhr.status == 200) ? "status good" : "status bad";
}
};
xhr.send();