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 trialSun Min
2,941 Pointsgetting information from a function
function getYear () { var year = new Date().getFullYear(); return year; }
getYear(); var yearToday = getYear();
what happen if i run this code? i called function and set a variable and call function again? what happens if we set variable = function?
1 Answer
Steven Parker
231,271 PointsThe plain function call doesn't really do anything.
This isn't the kind of function that makes something happen, it's the kind that returns a value. So just calling the function as a statement by itself will not do anything, or at least nothing that will leave a lasting result.
But assigning a variable with it will give that variable the return value, exactly what you might want.
Sun Min
2,941 PointsSun Min
2,941 PointsThanks Steven