
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.
66 lines
1.4 KiB
Plaintext
66 lines
1.4 KiB
Plaintext
== Why is this an issue?
|
|
|
|
``++undefined++`` is the value you get for variables and properties which have not yet been created. Use the same value to reset an existing variable and you lose the ability to distinguish between a variable that exists but has no value and a variable that does not yet exist. Instead, ``++null++`` should be used, allowing you to tell the difference between a property that has been reset and one that was never created.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,javascript]
|
|
----
|
|
var myObject = {};
|
|
|
|
// ...
|
|
myObject.fname = undefined; // Noncompliant
|
|
// ...
|
|
|
|
if (myObject.lname == undefined) {
|
|
// property not yet created
|
|
}
|
|
if (myObject.fname == undefined) {
|
|
// no real way of knowing the true state of myObject.fname
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,javascript]
|
|
----
|
|
var myObject = {};
|
|
|
|
// ...
|
|
myObject.fname = null;
|
|
// ...
|
|
|
|
if (myObject.lname == undefined) {
|
|
// property not yet created
|
|
}
|
|
if (myObject.fname == undefined) {
|
|
// no real way of knowing the true state of myObject.fname
|
|
}
|
|
----
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Use ``++null++`` instead.
|
|
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== on 10 Oct 2014, 17:26:20 Ann Campbell wrote:
|
|
Assigned to you for review [~linda.martin]
|
|
|
|
=== on 19 May 2015, 15:50:53 Linda Martin wrote:
|
|
Reviewed.
|
|
|
|
endif::env-github,rspecator-view[]
|