github-actions[bot] a3be39441e
Create rule S6645: Variables should not be initialized to undefined (#2218)
You can preview this rule
[here](https://sonarsource.github.io/rspec/#/rspec/S6645/javascript)
(updated a few minutes after each push).

https://github.com/SonarSource/SonarJS/issues/3922

## Review

A dedicated reviewer checked the rule description successfully for:

- [ ] logical errors and incorrect information
- [ ] information gaps and missing content
- [ ] text style and tone
- [ ] PR summary and labels follow [the
guidelines](https://github.com/SonarSource/rspec/#to-modify-an-existing-rule)

---------

Co-authored-by: alexander-kamushkin-sonarsource <alexander-kamushkin-sonarsource@users.noreply.github.com>
Co-authored-by: Alexander Kamushkin <alexander.kamushkin@sonarsource.com>
2023-06-19 17:00:04 +02:00

19 lines
813 B
Plaintext

== Why is this an issue?
Initializing a variable to `undefined` is unnecessary and should be avoided. A variable will automatically be set to `undefined` if you declare it without initialization, so the initialization code is redundant in this case.
[source,javascript]
----
var foo = undefined; // Non-compliant, replace with var foo;
let bar = undefined; // Non-compliant, replace with let foo;
----
== Resources
=== Documentation
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined[MDN - undefined]
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let[MDN - let]
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var[MDN - var]
* https://developer.mozilla.org/en-US/docs/Glossary/Hoisting[MDN - hoisting]