> For the complete documentation index, see [llms.txt](https://javascript-1.gitbook.io/javascript/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://javascript-1.gitbook.io/javascript/functions-as-object.md).

# Functions as Object

* The constructor of the function is an Object.

```javascript
Ex 1:
function welcome() {
    console.log("Wlecome"); // Welcome
}

welcome.greeting = "Hello";

Ex 2:
const obj = {
    greet() {
        console.log("Hello");
    }
};

obj.greet(); // Hello

```

In the above example 1 we declared a function welcome. We can print `"Welcome"` by calling as `welcome();`. Instead we can also use `call()` and `apply()` methods to call the same function. We know that `Object` only has the `key values`. Now clearly understood that function is also an Object.

```javascript
// under the hood of Ex 1
const welcome = {
    name: 'welcome',
    greeting: 'Hello',
    (): console.log("Wlecome")
}

```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://javascript-1.gitbook.io/javascript/functions-as-object.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
