12 lines
540 B
Plaintext
12 lines
540 B
Plaintext
![]() |
When a variable is assigned an <code>undefined</code> or <code>null</code> value, it has no properties. Trying to access properties of such a variable anyway results in a <code>TypeError</code>, causing abrupt termination of the script if the error is not caught in a <code>catch</code> block. But instead of <code>catch</code>-ing this condition, it is best to avoid it altogether.
|
||
|
|
||
|
== Noncompliant Code Example
|
||
|
|
||
|
----
|
||
|
if (x === undefined) {
|
||
|
console.log(x.length); // Noncompliant; TypeError will be thrown
|
||
|
}
|
||
|
----
|
||
|
|
||
|
include::../see.adoc[]
|