Now let's stick to functions for the moment
because there's one other thing you should be aware of
when we talk about functions
and that's stat behind the scenes,
internally, functions are in the end, just objects.
And that can be confusing because we did learn
that objects are these things with those curly braces,
which you create like this.
And then you could add a name which has max and the age,
which is 32 and do something like that.
That's an object.
That's what we learned before.
And objects have these key value pairs,
which are called properties,
which you can access with the dot notation
to set a new value or to read the value.
And you can also add methods to objects,
but functions are also objects.
And for that let's console log sumUp without parentheses.
So just the name of the function here.
With that, we are not executing the function,
but instead we are just getting a reference
to that function.
We're just pointing at that function and we are therefore
logging the function itself.
Instead of the result of calling the function.
That's what we do here instead, here in this line,
we output the result of calling that function because
we do have those parentheses here.
On the other hand in this line,
we are just outputting the function itself.
And if we do that and I save everything here,
if we execute this file,
what we see is this strange syntax here, function sumUp.
Now that's not telling us too much.
It tells us that we have some function here,
which is called sumUp,
but that's actually just how NodeJS outputs
this function object.
If we do the same thing in the browser,
simply because there we get a, a nicer, more useful output,
then we'll see something different.
And for that, I opened a brand new tab
and then the console here in the dev tools,
because in here, we can actually also write
some JavaScript code that will be evaluated.
And therefore here I'll just add a function called add,
which accepts two numbers, let's say,
and which then just returns.
Num one plus num two,
and we're writing it all in one line here.
And it's a very simple function because here,
I don't want to talk about this function too much,
but instead about that object, which every function is.
So for that, I'm writing a function here.
If I console log at here in the browser dev tools
in this console, which you can also use
to play around with some dummy code,
as you see here, and I hit enter here,
then we already get a slightly different output.
And if we now replace console log with console dir,
which is more useful when outputting objects,
then you also get a little arrow here, which you can click.
And if you click it, you'll see a couple of properties.
These are key value pairs, and these are key value pairs,
of an object, of the function object that every function is.
Now, these are not properties, which you added manually.
We haven't added any properties at all to this function.
Instead, these are properties which are
inferred automatically.
For example,
the name of the function is stored in a separate property
or the number of arguments.
The number of parameters this function takes
is stored in a length property.
Now, why do you need to know that, if you don't set
those properties on your own?
Well, not because we will start setting properties
on our functions, but because this is something
we encountered before already,
when we used express this express package,
then we did require it in our NodeJS code.
And we executed it like a function to create
this app object here.
That's what we did before.
Now in other places of the code.
We however, used that same express function,
which it seems to be, to then all of a sudden access
properties on that function.
And we were able to do that because the team that developed
the express package added some custom properties
to this express function, to add more functionality
to that express thing that you can use in your code,
you could do something similar in your own code
with your own functions as well.
You can use the sumUp function and use the dot notation
to add some property.
You can do that for all objects that you add new properties
by simply accessing properties that don't exist yet and
storing new values in them.
But of course, typically you don't do that
because it's not too useful.
The team that developed the express package did that though.
And I'm just emphasizing this again here.
So that it's clear that even though we
don't typically do that, we can do that.
We can add properties to functions
because functions behind the scenes are all just objects,
special kinds of objects, but still objects.
And that's why express could both be executed as a function
and then be used like a object when we access properties.
And that's just something which I wanted to bring up again
to make it clear why that code worked the way it did work.