I don't understand the return function!


#1

It works!

var timesTwo = function(number) {
return number * 2;
};
console.log(timesTwo(2));
var newNumber = timesTwo;

It comes up with 4 as it should! But how do I call it up again? I guessed it was:

console.log(newNumber);

but it just comes up with:

[Function: timesTwo]

So how do I call it up again if I need it later! Do I have to use:

console.log(timesTwo(2));

to call it up again?


#2

timesTwo is a function that needs an input(parameter) to call it eg

timesTwo(4);
timesTwo(16);
var num = 5;
timesTwo(num);

You can't simply assign a function to a variable and ditch their parameter. So you have to do

var newNumber = timesTwo(randomNumber);

#3

Thanks lots bro/ sis!


#4

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