Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

47 lines
1.3 KiB
Plaintext

== Why is this an issue?
When a variable is assigned an ``++undefined++`` or ``++null++`` value, it has no properties. Trying to access properties of such a variable anyway results in a ``++TypeError++``, causing abrupt termination of the script if the error is not caught in a ``++catch++`` block. But instead of ``++catch++``-ing this condition, it is best to avoid it altogether.
=== Noncompliant code example
[source,javascript]
----
if (x === undefined) {
console.log(x.bar); // Noncompliant; TypeError will be thrown
}
----
include::../see.adoc[]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
include::../highlighting.adoc[]
'''
== Comments And Links
(visible only on this page)
=== on 15 Mar 2016, 09:45:14 Pierre-Yves Nicolas wrote:
Useful links:
* \https://javascriptweblog.wordpress.com/2010/08/16/understanding-undefined-and-preventing-referenceerrors/
* \https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined
We could make this rule also cover invalid function calls, e.g.:
----
var x = 42;
x(); // Noncompliant: TypeError will be thrown
----
However, there may be some overlap with RSPEC-2999.
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]