Functions Are Objects

Query

```js function myMethod() { return 1; }

myMethod.foo = bar;

console.log(method()); console.log(method.foo); ```

```js function myMethod() { return 1; }

console.log(myMethod.name); ```

Discussion

```js function test() { return 1; }

test.foo = 'bar';

console.log(test()); console.log(test.foo); console.log(test.name); ```

Here we will get output

bash 1 bar test

Here we can add a property in the function, just like an object.

Internally, when we define a object in Javascript, it interpret the Test function, we defined earlier, something like the following object

js const specialFunctionMethod = { name: 'test', foo: 'bar', (): 'return 1' }

Whenever we create a method, internally a object is being created with the following properties

Final Thought