I have a script which I launch using terminal and it always works well but sometimes randomly it throws following error:
TypeError: Cannot read property 'Name' of undefined
This script goes through same lines of code thouthands of times before it crashes because of this error. Here's the problematic line:
setTimeout(function() {deleteAlert(data[This].Name, intent); }, 2000);
How do I prevent my program from crashing? I tried doing this:
if (data[This] && data[This].Name) { setTimeout(function() {deleteAlert(data[This].Name, intent); }, 2000); } else { console.log(colors.red('ATTENTION: ') +"alert not deleted"); }
But it still sometimes throws an error at the same line. I mean it passes through data[This] && data[This].Name
succesfully and then hits an error. How do I change this condition so that this error will not crash my script?