JS Return Keyword


#1

Hey guys, I am having a little trouble with the return keyword. First of all, what exactly does it do and what can it be used for? I wasn't too clear on that. I am also having problems with the exercise for this lesson. The interpreter says I did not print out the value of newNumber.

var timesTwo = function(number) {
return number * 2;
};

timesTwo(8);
var newNumber = function(number){
console.log(newNumber);
}
newNumber(5);

Any help would be greatly appreciated! Thanks! :slight_smile:


#2

Syntax
return [[expression]];

A _return_ statement causes a function to cease execution and return a value to the caller. If Expression is omitted, the return value is undefined. Otherwise, the return value is the value of Expression.

I didn't find the lesson, but I think should be:
1. Create function timesTwo which takes 1 parameter and returns new value for it parameter.
2. Define variable newNumber and assign it to result of timesTwo function execution:

var newNumber = timesTwo(5);

3. Call console.log() method and put newNumber as an argument.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.