All processing happens locally in your browser · No data uploaded
JavaScript Formatter
Format any JavaScript or TypeScript code with Prettier-style formatting. Supports ES2022+, JSX, TypeScript, and module syntax.
Input JavaScript
Output · 491 chars
function calculateTotal(items, taxRate) {
const subtotal = items.reduce((sum, item) => {
return sum + item.price * item.quantity;
}
, 0);
const tax = subtotal * taxRate / 100;
const total = subtotal + tax;
return {
subtotal, tax, total }
;
}
const cart = [
{
name: 'Widget', price: 29.99, quantity: 2 }
,
{
name: 'Gadget', price: 49.99, quantity: 1 }
];
const result = calculateTotal(cart, 18);
console.log(result);JS Format Style (Prettier defaults)
Print width: 80 Tab width: 2 spaces Single quotes Semicolons: yes Trailing commas: ES5 Bracket spacing: yes
Examples
Minified function
Result: function add(a, b) { return a + b; } const result = add(1, 2); console.log(result);
Proper spacing, indentation, and line breaks added.
Frequently Asked Questions
Does it support TypeScript?
Yes. TypeScript syntax including type annotations, interfaces, generics, and decorators are all handled.
Does it support JSX/React?
Yes. JSX elements and React-specific syntax are properly formatted.