1
00:00:02,110 --> 00:00:04,380
So functions in objects is a thing,

2
00:00:04,390 --> 00:00:10,020
what if I would tell you that functions themselves also are objects?

3
00:00:10,240 --> 00:00:11,770
I can prove this,

4
00:00:11,770 --> 00:00:19,630
if I console log typeof start game, you might remember this typeof operator, we used that earlier in

5
00:00:19,630 --> 00:00:23,850
the course to find out what the type of an array and of a number and so on is.

6
00:00:23,890 --> 00:00:30,190
Now if I log the typeof my start game function, so I'm not executing it because that would call the

7
00:00:30,190 --> 00:00:35,410
function and I would get the typeof whatever this function returns, which is nothing which therefore

8
00:00:35,410 --> 00:00:39,210
would be undefined, as you see if you reload, you see undefined here,

9
00:00:39,550 --> 00:00:41,370
so that's not what I'm interested in.

10
00:00:41,530 --> 00:00:45,790
If I log it like this, I am basically doing the same as with the event listener,

11
00:00:45,790 --> 00:00:52,000
I'm just passing the name here and therefore the typeof operator will have a look at the thing behind

12
00:00:52,000 --> 00:00:52,600
the name,

13
00:00:52,600 --> 00:00:57,730
so it will have a look at that thing which is stored in start game, which is our function

14
00:00:57,730 --> 00:01:04,030
and if we do that if I log the typeof my function here, then if I reload you see function here.

15
00:01:04,150 --> 00:01:04,360
Okay,

16
00:01:04,360 --> 00:01:10,480
that's not an object right, that's a function. Well actually, function is a separate type which is being

17
00:01:10,480 --> 00:01:16,300
logged here but it's based on object. It becomes a bit easier to see if I don't log the type

18
00:01:16,300 --> 00:01:17,710
but the function like this,

19
00:01:17,710 --> 00:01:20,590
so I'm not calling the function, I'm just passing the name here,

20
00:01:20,710 --> 00:01:23,670
so therefore I log the thing behind the function.

21
00:01:23,680 --> 00:01:29,590
Now let's also switch console log to console dir which gives us a different insight into objects

22
00:01:30,010 --> 00:01:36,190
and if we then go back and reload here, you see here we get this strange thing here, looks like a function but

23
00:01:36,190 --> 00:01:41,020
I can expand it and what you see here is actually, there's a bunch of strange stuff in it,

24
00:01:41,110 --> 00:01:46,610
we got a name for example, we got an arguments thing and these are all key-value pairs in there,

25
00:01:46,630 --> 00:01:50,140
so these are all properties of this function in the end.

26
00:01:50,200 --> 00:01:53,140
Now it also has a scopes thing and that's interesting,

27
00:01:53,130 --> 00:01:57,590
this basically tells Javascript where to manage the variables of these functions, so what the scope and

28
00:01:57,610 --> 00:01:58,450
on is

29
00:01:58,780 --> 00:02:01,550
and we don't need to worry too much about the stuff that's in there,

30
00:02:01,570 --> 00:02:06,490
some of the things like prototype will become clearer later in the course once we dive way deeper into

31
00:02:06,490 --> 00:02:10,540
objects and how they work internally, not something we have to worry about right now.

32
00:02:10,540 --> 00:02:16,650
The only key takeaway right now is that a function in the end whilst having its own type is an object.

33
00:02:16,660 --> 00:02:22,570
It's basically also an object, a special type of object if you will with special pre-configured properties

34
00:02:22,900 --> 00:02:30,400
but still an object and the implication of that is for example that it's typically stored in the heap

35
00:02:30,490 --> 00:02:35,680
as you learned and basically anything that applies to objects, for example that they are reference

36
00:02:35,680 --> 00:02:41,620
types also applies to functions. Often that might not really matter to you, it's still important to be

37
00:02:41,620 --> 00:02:42,540
aware of that,

38
00:02:42,580 --> 00:02:45,070
so functions are objects.
