-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.js
More file actions
33 lines (27 loc) · 1 KB
/
1.js
File metadata and controls
33 lines (27 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Predict and explain first...
// =============> write your prediction here
//The output will be:
// "The sum of 10 and 32 is not defined because the return statement without a value.
// The line "a + b;" after return will not executed
// return undefined. The code after return is unreachable.
function sum(a, b) {
return;
a + b;
}
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
// =============> write your explanation here
// a + b; ← This line will not executes (unreachable code)
// So the function effectively becomes:
// function sum(a, b) {
// return undefined;
// a + b; // not execute
// }
// The return statement immediately exits the function and returns undefined.
// Any code after a return statement is "unreachable" and not execute.
// result is the sum of 10 and 32 is undefined"
// Finally, correct the code to fix the problem
// =============> write your new code here
function sum(a, b) {
return a + b;
}
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);