Variable 'emailUndefined' should be initialized on declaration
165 it("should throw an error if 'email' is undefined", () => {
166 const name = 'Bob';
167 const id = 20;
168 let emailUndefined;169 const officeNumber = 1001;
170
171 const cb = () => new Manager(name, id, emailUndefined, officeNumber);
Variable 'idUndefined' should be initialized on declaration
95
96 it("should throw an error if 'id' is undefined", () => {
97 const name = 'Bob';
98 let idUndefined; 99 const email = '[email protected]';
100 const officeNumber = 1001;
101
Variable 'nameUndefined' should be initialized on declaration
50 });
51
52 it("should throw an error if 'name' is undefined", () => {
53 let nameUndefined; 54 const id = 20;
55 const email = '[email protected]';
56 const officeNumber = 1001;
Variable 'emailUndefined' should be initialized on declaration
165 it("should throw an error if 'email' is undefined", () => {
166 const name = 'Daniel';
167 const id = 1;
168 let emailUndefined;169 const school = 'University of Arizona';
170
171 const cb = () => new Intern(name, id, emailUndefined, school);
Variable 'idUndefined' should be initialized on declaration
95
96 it("should throw an error if 'id' is undefined", () => {
97 const name = 'Daniel';
98 let idUndefined; 99 const email = '[email protected]';
100 const school = 'University of Arizona';
101
Variable 'nameUndefined' should be initialized on declaration
50 });
51
52 it("should throw an error if 'name' is undefined", () => {
53 let nameUndefined; 54 const id = 1;
55 const email = '[email protected]';
56 const school = 'University of Arizona';
Variable 'emailUndefined' should be initialized on declaration
165 it("should throw an error if 'email' is undefined", () => {
166 const name = 'Daniel';
167 const id = 2;
168 let emailUndefined;169 const github = 'danielfloresd';
170
171 const cb = () => new Engineer(name, id, emailUndefined, github);
Variable 'idUndefined' should be initialized on declaration
95
96 it("should throw an error if 'id' is undefined", () => {
97 const name = 'Daniel';
98 let idUndefined; 99 const email = '[email protected]';
100 const github = 'danielfloresd';
101
Variable 'nameUndefined' should be initialized on declaration
50 });
51
52 it("should throw an error if 'name' is undefined", () => {
53 let nameUndefined; 54 const id = 2;
55 const email = '[email protected]';
56 const github = 'danielfloresd';
Variable 'idUndefined' should be initialized on declaration
79
80 it("should throw an error if 'id' is undefined", () => {
81 const name = 'Dan';
82 let idUndefined; 83 const email = '[email protected]';
84
85 const cb = () => new Employee(name, idUndefined, email);
Variable 'nameUndefined' should be initialized on declaration
45 });
46
47 it("should throw an error if 'name' is undefined", () => {
48 let nameUndefined; 49 const id = 2;
50 const email = '[email protected]';
51
Description
In JavaScript, variables can be assigned during declaration, or at any point afterwards using an assignment statement. For example, in the following code, foo
is initialized during declaration, while bar
is initialized later.
var foo = 1;
var bar;
if (foo) {
bar = 1;
} else {
bar = 2;
}
Bad Practice
function foo() {
var bar;
let baz;
}
Recommended
function foo() {
var bar = 1;
let baz = 2;
const qux = 3;
}