return
StatementIn CustomJS, the JavaScript you write has to explicitly tell Make what value to send back. The only way to do that is with a return
statement.
If you don’t include return
, the code may run internally, but Make won’t receive any result, so the workflow won’t have any output to continue working with.
Aspect | Without Return | With Return |
---|---|---|
Code | // Example (won't return a value to Make)
const fullName = `${input.name} ${input.lastname}`;
// No return statement below — Make receives nothing | // Example (returns a value to Make)
const fullName = `${input.name} ${input.lastname}`;
return fullName; |
Result | Make receives no output. The next module has nothing to use, so the workflow may fail or produce empty values. | Make receives the string (e.g., "John Doe" ). This value can now be used in subsequent modules. |
Use early returns to stop execution when required input is missing or invalid. Returning immediately when something is wrong avoids running the rest of the code and makes debugging easier.
Aspect | Without early return | With early return |
---|---|---|
Code | // Incorrect: runs even with missing input
const processedEmail = input.email.toLowerCase();
return { processedEmail };
| // Correct: return early if input is missing
if (!input.email) {
return { error: "Email is required" };
}
|
Result | Code crashes if input.email is undefined.
The workflow may fail with an error. | Code stops gracefully when input.email is missing.
Make receives a clear error message instead of breaking. |
Always return data in the same shape (e.g., object with predictable keys). This makes downstream modules easier to configure, since they know what to expect regardless of success or failure. Moreover, a predictable output format prevents “undefined property” errors and simplifies mapping in Make.
Aspect | Inconsistent | Consistent |
---|---|---|
Code | // Incorrect: returns different structures
if (input.success) {
return input.data;
} else {
return "Processing failed";
}
| // Correct: always return the same shape
if (input.success) {
return {
status: "success",
data: input.data,
message: "Processing completed"
};
} else {
return {
status: "error",
data: null,
message: "Processing failed"
};
}
|
Result | Downstream modules can’t predict the format. This causes mapping errors or undefined values. | Downstream modules always get a predictable object. This makes mapping and error handling reliable. |
When using asynchronous code (like fetch
, database calls, or API requests), await the result and then return it. If you forget await
or don’t return the resolved value, Make will just get a pending Promise, not usable data.
Aspect | Without await | With await |
---|---|---|
Code | // Incorrect: returns a Promise, not data
return fetch(input.url).then(res => res.json());
| // Correct: resolve the Promise before returning
const response = await fetch(input.url);
const data = await response.json();
|
Result | Make receives a Promise instead of usable data. The next module cannot work with unresolved Promises. | Make receives the actual data (JSON object with status and content). The next module can directly use this result. |
Since we wrap your JavaScript code with an async expression, we recommend always defining return statements and ending inline functions with a semicolon.
{ }
function fullName(firstName, lastName){ return `${firstName} ${lastName}`};
return fullName("John", "Doe");
{ output: "John Doe" }
With this help you ensure that your code runs smoothly and efficiently, especially when
working with complex javscript function calls in Make.com.
Increase your flexibility in data processing by retrieving the values of input fields
directly via the JavaScript variable "input" or by creating JSON objects for complex
scenarios, as described in our guide on the example page for
JSON Parameter