Tell us what’s happening:
Hello all.
So i’m on the lesson where we are learning about functions without return statements.
in the example given, on the text bit (link to lesson: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/understanding-undefined-value-returned-from-a-function) it says that calling the function (using an argument of 3) will change the global sum variable but the returned value of the output is undefined.
two questions:
-
does this mean that if i called the function again with an argument of 5 (ie addThree(5); ) that will change the value of the global sum variable to 8?
-
what does it mean by output is undefined? As far as i can see, we haven’t asked for an output (ie a console.log(function) anywhere in the code, so i can’t see where/what is being output as undefined?
Hope that makes sense, thanks in advance!
Matt
Your code so far
// Setup
var sum = 0;
function addThree() {
sum = sum + 3;
}
// Only change code below this line
// Only change code above this line
addThree();
addFive();
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36
.
Challenge: Understanding Undefined Value returned from a Function
Link to the challenge: