Developer

JS Function Tester

Compile a small function from an expression (arrow, anonymous, or wrapped function expression) or from a parameter list + body, then call it with JSON arguments. See the return value, timing, and errors — all evaluated in your browser tab (no server). This is not a security sandbox; use only code you trust.

Ad placement — top banner
Definition mode

Must evaluate to a function — for example (x) => x * 2, function (a, b) { return a + b; }, or (function () { return 1; }).

Use [] for zero-argument functions. Values are passed positionally to fn.apply(null, args).

Ad placement — mid rectangle

What is a function tester?

A function tester lets you quickly try a small JavaScript function with a chosen set of arguments and inspect the result without creating a file or a full test project. It is useful for debugging arithmetic, array transforms, and pure helpers — the same things you might otherwise type into the browser console.

How this tool works

In Function expression mode, your code is wrapped as new Function('return (' + yourCode + ')')() so the expression must evaluate to a callable function. In Parameters + body mode, your parameter names and body are passed to new Function directly. Arguments are parsed as JSON and applied with fn.apply(null, args). Return values are pretty-printed: primitives as text, objects and arrays with JSON.stringify when possible, and a short note if a Promise is returned (this page does not await).

  • Optional performance.now() timing for each run (shown in the stats row).
  • Runtime errors show message and stack in the output area.
  • No network — your code never leaves this tab.

Safety and limitations

Code runs in the same page as the tool: it can touch the page DOM, storage, and network APIs if you write that. This is not an isolated sandbox like a VM or a locked-down iframe. Do not paste untrusted code. Infinite loops will freeze the tab until the browser stops the script.

How to use this tool

  1. Step 1: Pick expression mode or parameters + body.
  2. Step 2: Enter your function and a JSON array of arguments.
  3. Step 3: Click Run and read the result, duration, and type in the stats row.
  4. Step 4: For async functions, use DevTools or your own harness to await promises.

Frequently Asked Questions

Does DroidXP upload my code?

No. Compilation and execution happen in your browser. For confidential logic, still follow your organization’s policies on using web-based tools.

Is this a secure sandbox?

No. The function runs in the same JavaScript realm as the page. It is not suitable for running untrusted or unknown code. Use dedicated VMs or isolated environments for that.

Why does my function declaration fail?

Bare declarations like function f() {} are statements, not expressions. Use an arrow or anonymous function expression that evaluates to a function, or switch to Parameters + body mode.

Why did I get a Promise message instead of a value?

async functions return promises. This tool does not await; chain .then() in a console snippet or test async code elsewhere.

Can I import modules or use TypeScript?

No. Paste plain JavaScript that runs in the browser. For modules and TypeScript, use your bundler or a local playground.

Why does the tab freeze?

Synchronous infinite loops or long blocking work cannot be interrupted from this UI. Keep snippets small and avoid tight loops on large data.

How do I pass objects or arrays?

Use JSON in the arguments field — for example [{"x":1}, [2,3]]. JSON does not support undefined, functions, or symbols as values.