Undefined behaviour (Definition)

Erroneous operations not described in the standard.

Undefined behavior is what happens when something goes wrong but the standard does not provide any suggested behavior. In many languages, an attempt to divide by zero would yield an undefined result. However JavaScript defines the NaN value for just such an occasion.

These situations generally manifest themselves as a run-time error which at the least would present an alert to the user. Sometimes the implementation can catch these errors and may offer the opportunity to stop executing scripts on that web page.

In some cases, the undefined behavior may degenerate to the worst case scenario where the hosting application or even the environment itself is compromized and the system crashes. An example of this is some versions of Netscape when presented with an <OBJECT> tag and some versions of MSIE when onmouseover events cross from one DOM object to another. In both cases, the browser crashes and does so in such a way that the underlying operating system is also stalled, necessitating a complete reboot.

A portable script should not depend on any undefined behavior performing in a predictable way, even if that behavior is benign. It is very likely that any undefined behavior will not survive between versions of the implementation and almost certainly will not be portable across platforms.

See also:Behavior, Portability, Range error