[SOUND] Okay, so now that we spoke about objects,
it's time to speak about what functions really are underneath in JavaScript.
I'm located in script.JS, and that is sitting inside the lecture 46 folder.
Let me close the file browser here.
And let's take a look at a very simple function, here function multiply and
it takes two arguments x and y and returns just a multiplication of x and y.
So the first thing I want you to know is that functions
in JavaScript are what's called, first class data types.
What that means is, is that whatever you could do with the variable,
whatever you could do with an object you could also do with the function.
You could pass that around, assign it to a variable which as you've seen before,
you could pass it as an argument to another function,
you could return it as a return result from a function.
Functions in JavaScript are objects.
They're regular objects that have some special properties to them.
So since they're regular objects, I should be able to set properties on them
just like I set properties on the other object.
So for example, here I have a function called multiply.
And let's test that it works.
Let's do multiply let's say 5 to 3, multiple 5 by 3, and
if we save that we'll see that,
I forgot to console it out, let's console.log(multiply(5, 3)).
And we should see 15 and we do.
Okay, so now what I could do is I got set a property on the multiply
function just like I set on any other object.
Let's go ahead and set a property called multiply.version and
let's set it to version V.1.0.0.
And let's go ahead and console that log and
let's console that log the actual function multiply.
So we're not actually calling the function.
If we call the function, we would have to put the parenthesis after it.
But we actually just want to output the value of the function.
Let's go ahead and output the value of the function.
Let's save that and we forgot to put console.log.
No problem.
We'll fix that.
And the value of function is the function code itself.
So the reason that's happening is because every object has this inherent method or
inherent function to it that's called to strings.
So if we do toString, and call to string and we're going to save that and
get exactly the same thing.
So what we want to do is actually get that property version.
So if we do, multiply that version, and
now we save that, you'll see that the version has been set on our function.
So our function is nothing more then an object.
Now the fact that it's an object allow us to do quite
a number of interesting things that are so useful in every application.
Let's go ahead and actually erase a couple of these code statements so
we'll just have the multiplied version.
And what we'll do is we'll start making function factories.
Okay, so let's call this Function factory.
So what we're going to do is we're going to create a function.
And the function's going to to be called makeMultiplier.
And we're going to provide a multiplier for it.