When a piece of javascript code gives an error in the console. How can I do something like: If this piece of code gives back an error execute another piece of code?
This is what I have:
try {
var operator = <?=$this->shopRequest[operator]?>;
} catch(errorObj) {
var operator = sessionStorage.getItem('operator');
}
This is the error I get in the console:
Uncaught SyntaxError: Unexpected token ;
try...catch<?=$this->shopRequest[operator]?>. I would imagine it doesn't include the required quotes$this->shopRequest[operator]apparantly isn't what you expect it to be, so have a look at it. If it is supposed to be a string, maybe it would be enough to add quotes:var operator = "<?=$this->shopRequest[operator]?>";