Kinda lost and need some help


It works fine, and I passed the lesson, I just need some help with how this works.

// Parameter is a number, and we do math with that parameter
var timesTwo = function(number) {
    return number * 2;

// Call timesTwo here!
var newNumber = timesTwo(15);

Ok I passed my lessen, but I needed to use the "Stuck" button. I understand what a function is, and why we use it. But I do not understand how this code above actually completes. How does it know what number is === number when we are calling newNumber and not number. It is very confusing and if someone could explain I would be very grateful. I am not the smartest guy in the world, but I love to code, and I am trying to get better.


Your timesTwo function takes a number and multiplies it by 2. Then you created a variable called newNumber which equals timesTwo(15). Then you logged newNumber to the console.

In your timesTwo function, number is the parameter timesTwo multiplies by 2. NewNumber is a variable equivalent to timesTwo(15) which executes as 15 * 2. If you called timesTwo again with 10 as the input, the value changes to 20. If you call newNumber again, newNumber is still equal to timesTwo(15).


Yes I understand all that. What I am not understanding is how the computer knows what 'number' is when we NEVER call it or set a var for it. We have newNumber, but thats different from number. So how does the computer know how to complete this?


I don't know how the computer knows either. My assumption is in javascript, number means not a string.


newNumber has no connection in general with number. But when we equate var newNumber = timesTwo(15)
it calls the function timesTwo that takes the number as 15 and does the following code and returns 30 i.e) your newNumber.


Because it is not in double qoutes so it takes as an integer.


Yes we understand this, but basic principle tells us everything has to be called. Studying the code above, there is nothing linking any vars to number. So it is very confusing on how the computer knows what to do.

I understand how the code works, what I do not understand is how the computer knows we are subbing our actual number for their 'number'.


I don't understand this 100% but the gist of it seems to be, certain words have universal definitions in javascript.


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