When one first starts programming, there can often be confusion about the difference between logging something to the console and in a value, since they both seem to output some value to the computer screen.
You are only allowed to return values in functions. One of the purpose of a function is to take inputs which are called arguments, process that data, and then you RETURN a result. The returned result is data given back to the program for further use. For example
function add(a, b) {
return a + b;
}
var result = add(2, 5);
//7 is returned and stored in the variable "result". You can use this value in further operations.
now if you do something such as
var result2 = console.log(2 + 5)
// 7 will be output to the screen. watch what happens when you 'log' the value to see the actual value stored in result2
console.log(result2)
// returns undefined
When you define a function, you specify 'parameters. A and B are parameters. When you call, aka invoke a function, you specify arguments to that function. So in the above example "a" and "b" are parameters of function add. When add is called, "2" and "5" are arguments to that function. What is returned is 7, which is stored in the variable result. Something interesting about Javascript is that functions always return a value, even if you don't have a return statement. If you don't specify a return statement, 'undefined' is returned by the function.
Now, when you "log" a value, such as using the console.log method, you are merely using the log method of the console object. A method is merely a function that belongs to a particular object. In this case, the log function belongs to the console object, hence it being the 'log method'. Now, console.log out puts a value to the screen and that is all it does. As 'log' is a method that does not explicitly return a value, 'undefined is returned'. You do not get back data that you are able to further manipulate with console.log as you do with return