Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Errors in javascript programs [closed]

Tags:

javascript

Is there a good classification of standard javascript errors? For example, in java like programs, there are errors like ArrayIndexOutOfRange, resource leaks, race conditions etc.

Also, in Javascript few errors are not reported as exceptions (e.g., divide by zero). Are there any other similar behaviors that are not reported as runtime exceptions in javascript?

like image 983
dmonji Avatar asked Feb 28 '26 22:02

dmonji


1 Answers

MDN has a great article about this, they can put it better than I ever could:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#Error_types

Also, good classification here in the ECMA standard:

ECMAScript 5.1 (Current): http://www.ecma-international.org/ecma-262/5.1/#sec-15.11.6

ECMAScript 6 (Coming soon, some features already here in certain browsers): http://www.ecma-international.org/ecma-262/5.1/#sec-15.11.6

In terms of "not being reported as runtime errors", there are some evaluations of expressions that do not halt execution of code but return indicators like NaN, e.g.:

var a = "Hello";
var b = 3;
var c = a / b; // c is "NaN"

You can use the isNaN() function to check for this. Unfortunately I don't know of an offical definite list of these scenarios (if there are more) or even how you would classify them. I guess it comes down to experience and learning the features (or quirks depending on your perspective!) of the language.

like image 194
Stuart Bennett Avatar answered Mar 03 '26 12:03

Stuart Bennett



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!