I was reading the book Professional Javascript For Web Developers, and saw the following code. I have some questions about it:
function matchesSelector(element, selector){
if(element.matchesSelector){
return element.matchesSelector(selector);
}else if(element.msMatchesSelector){
return element.msMatchesSelector(selector);
}else if(element.mozMatchesSelector){
return element.mozMatchesSelector(selector);
}else if(element.webkitMatchesSelector){
return element.webkitMatchesSelector(selector);
}else{
throw new Error("Not supported!");
}
}
if(matchesSelector(document.body, "body.page1")){
//do somthing
}
When an error is thrown, if it is not caught using a try...catch block, the scope execution just stops.
Nothing is returned by that function, and if that function's return value is used somewhere in if statement, that if statement block is not executed as well.