Skip to content

Commit 1314659

Browse files
exercise-1.js: remove unreachable and redundant code
1 parent 29ef74a commit 1314659

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

‎dead-code/exercise-1.js‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
// Find the instances of unreachable and redundant code - remove them!
22
// The sayHello function should continue to work for any reasonable input it's given.
33

4-
let testName = "Jerry";
4+
const testName = "Aman";
55
const greeting = "hello";
66

77
function sayHello(greeting, name) {
8-
const greetingStr = greeting + ", " + name + "!";
8+
99
return `${greeting}, ${name}!`;
10-
console.log(greetingStr);
10+
1111
}
1212

13-
testName = "Aman";
13+
1414

1515
const greetingMessage = sayHello(greeting, testName);
1616

1717
console.log(greetingMessage); // 'hello, Aman!'
18+
19+
20+
//Edit line 4 let testName = "Jerry"; to const testName = "Aman"; to avoid reassignment of a constant variable.
21+
//Remove line 8 const greetingStr = greeting + ", " + name + "!"; as it is redundant and not used in the function.
22+
//Remove line 10 console.log(greetingStr); as it is unreachable code and will never be executed.
23+
//Remove line 13 testName = "Aman"; as it has became redundant

0 commit comments

Comments
 (0)