2023-05-03 11:06:20 +02:00
== Why is this an issue?
2023-06-20 10:20:09 +01:00
The `void` operator evaluates its argument and always returns `undefined`.
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,javascript]
2021-04-28 16:49:39 +02:00
----
void doSomething();
----
2023-06-20 10:20:09 +01:00
It can be useful to prevent reassigning `undefined` in pre-ECMAScript 5 environments. However, using `void` makes code more difficult to understand.
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,javascript]
2021-04-28 16:49:39 +02:00
----
doSomething();
----
2023-05-03 11:06:20 +02:00
=== Exceptions
2021-04-28 16:49:39 +02:00
2022-08-04 15:12:16 +02:00
No issue is raised when ``++void 0++`` is used in place of ``++undefined++``.
2021-04-28 16:49:39 +02:00
2022-08-04 15:12:16 +02:00
[source,javascript]
2021-04-28 16:49:39 +02:00
----
if (parameter === void 0) {...}
----
2022-02-18 09:28:27 +01:00
No issue is raised when ``++void++`` is used before immediately invoked function expressions.
2021-04-28 16:49:39 +02:00
2022-08-04 15:12:16 +02:00
[source,javascript]
2021-04-28 16:49:39 +02:00
----
void (function() {
...
}());
----
2021-04-28 18:08:03 +02:00
2022-02-18 09:28:27 +01:00
No issue is raised when ``++void++``'s argument is a promise.
2022-08-04 15:12:16 +02:00
[source,javascript]
2022-02-18 09:28:27 +01:00
----
const promise = new Promise((resolve, reject) => {
setTimeout(() => {
resolve('done');
}, 3000);
});
void promise;
----
2021-06-02 20:44:38 +02:00
2023-06-20 10:20:09 +01:00
== Resources
=== Documentation
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/void[MDN - Void]
2021-06-03 09:05:38 +02:00
ifdef::env-github,rspecator-view[]
2021-09-20 15:38:42 +02:00
'''
== Implementation Specification
(visible only on this page)
2023-05-25 14:18:12 +02:00
=== Message
Remove this use of the 'void' operator.
=== Highlighting
``++void arg++``
2021-09-20 15:38:42 +02:00
2021-06-08 15:52:13 +02:00
'''
2023-06-20 10:20:09 +01:00
2021-06-02 20:44:38 +02:00
== Comments And Links
(visible only on this page)
2023-05-25 14:18:12 +02:00
=== on 30 Sep 2016, 10:14:28 Elena Vilchik wrote:
\[~ann.campbell.2] Hi! Could you finish this ticket? Thanks!
(I'm struggling to define severity)
=== on 30 Sep 2016, 16:47:30 Ann Campbell wrote:
\[~elena.vilchik] could you supply some code samples?
=== on 30 Sep 2016, 17:13:13 Elena Vilchik wrote:
\[~ann.campbell.2] done
=== on 14 Mar 2017, 10:33:27 Elena Vilchik wrote:
\[~ann.campbell.2] Hi! we added exclusion to this rule: ``++void 0++`` used as ``++undefined++``. Could you update main part of description, as it's outdated now. Thanks!
2021-06-03 09:05:38 +02:00
endif::env-github,rspecator-view[]