Skip to content

Commit ddcbe99

Browse files
committed
fix(sprint-2): move return statement after calculation in sum function
1 parent de47a6e commit ddcbe99

File tree

1 file changed

+8
-0
lines changed
  • Sprint-2/2-mandatory-debug

1 file changed

+8
-0
lines changed

Sprint-2/2-mandatory-debug/1.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
// Output: "The sum of 10 and 32 is undefined"
4+
// Return statement has no value, so returns undefined. Expression "a + b" is unreachable code
35

46
function sum(a, b) {
57
return;
@@ -9,5 +11,11 @@ function sum(a, b) {
911
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
1012

1113
// =============> write your explanation here
14+
// Bug: return; exits immediately without a value (returns undefined). Code after return never executes
15+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return
16+
1217
// Finally, correct the code to fix the problem
1318
// =============> write your new code here
19+
function sum(a, b) {
20+
return a + b;
21+
}

0 commit comments

Comments
 (0)