Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialjohn knight
Courses Plus Student 9,155 PointsQuestion, Any help will be appreciated
Question: I've got complicated about the return value and the calling the function. I've understood that if we used the return value we don't need the function calling am i right or not?.
2 Answers
Kyle Johnson
33,528 PointsHi John!
I'm a little confused on what you are asking but I'll attempt to answer your question anyways. The two code blocks below both print 5 to the console. You are still calling the function in both examples. The first example calls the function inside the console.log() while the second calls the function on its own line.
function giveMeFive() {
return 5;
}
// prints 5 to the console
console.log( giveMeFive() );
vs
function giveMeFive() {
console.log("5");
}
// prints 5 to the console
giveMeFive();
Steven Parker
231,236 PointsThis would not be likely in a real-world situation.
If you can obtain the return value without calling the function, it's probably because you are looking at a trivial example provided just for instructional purposes. In a real-world situation, you would not have a function unless it was necessary to obtain the return value.