0
0
Javascriptprogramming~5 mins

Return values in Javascript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the return statement do in a JavaScript function?
It stops the function and sends a value back to where the function was called.
Click to reveal answer
beginner
Can a JavaScript function return more than one value directly?
No, a function returns only one value. But you can return an object or array to hold multiple values.
Click to reveal answer
beginner
What happens if a function does not have a return statement?
The function returns undefined by default.
Click to reveal answer
beginner
How do you capture the value returned by a function?
You assign the function call to a variable, like <code>let result = myFunction();</code>
Click to reveal answer
beginner
What is the difference between console.log() and return in a function?
console.log() shows output on the screen but does not send a value back. return sends a value back to the caller.
Click to reveal answer
What does a return statement do inside a function?
AStops the function and sends a value back
BPrints a value to the console
CStarts the function
DDeclares a variable
What value does a function return if it has no return statement?
Anull
B0
Cundefined
Dfalse
How can you return multiple values from a function?
AYou cannot return multiple values
BUse multiple <code>return</code> statements
CReturn a string with all values
DReturn an array or object containing the values
Which of these captures the returned value from a function?
Alet x = myFunction()
Bconsole.log(myFunction())
Creturn myFunction()
Dfunction myFunction()
What is the difference between return and console.log()?
A<code>return</code> prints output, <code>console.log()</code> sends value back
B<code>return</code> sends value back, <code>console.log()</code> prints output
CBoth do the same thing
DNeither sends value back
Explain what the return statement does in a JavaScript function and why it is useful.
Think about how functions give you answers.
You got /3 concepts.
    Describe how you can return multiple values from a function in JavaScript.
    Imagine putting things in a box to carry them all at once.
    You got /3 concepts.