JavaScript Function Methods

About This Index
This page is the JavaScript Function Methods index. Every function has four methods. Each row below links to a full guide with syntax, examples you can run, and FAQs.
Learn what a function is on /js/function. Use this page when you need a specific method such as bind().
Write the function name, a dot, then the method: greet.call(user), greet.apply(user, [...]), greet.bind(user) and greet.toString().
How to Call a Function Method
Call the methods on any function:
function introduce(greeting) {
return greeting + ", I am " + this.name;
}
const user = { name: "Ava" };
console.log(introduce.call(user, "Hello")); // run now, arguments one by one
console.log(introduce.apply(user, ["Hello"])); // run now, arguments in an array
const bound = introduce.bind(user); // new function, this is locked
console.log(bound("Hello"));
console.log(introduce.toString().length > 0); // the code as text JavaScript Function Methods Table
All method guides in this JavaScript tutorial series (4 tutorials), grouped by what they do.
Run a function with a chosen this
2 methodsBoth methods run the function immediately. They differ only in how you pass the arguments.
Create a new function
1 methodPrepare a function now and run it later.
Read a function as text
1 methodSee the code of a function.
| Method | Description | Tutorial |
|---|---|---|
toString() | Return the code of a function as text. JavaScript calls it for you in String(fn) and in "text" + fn. | Open |
Frequently Asked Questions
Start with call()
Open the guide for running a function with a chosen this value: syntax, examples, and FAQs.
10 people found this page helpful
