🌐
Beautifier
beautifier.io
Online JavaScript beautifier
Chrome, in case the built-in CSS and javascript formatting isn't enough for you: — Quick source viewer by Tomi Mickelsson (github, blog), — Javascript and CSS Code beautifier by c7sky, — jsbeautify-for-chrome by Tom Rix (github), — Pretty Beautiful JavaScript by Will McSweeney — Stackoverflow Code Beautify by Making Odd Edit Studios (github).
🌐
W3Schools
w3schools.com › js › js_date_formats.asp
JavaScript Date Formats
The ISO format follows a strict standard in JavaScript.
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Text_formatting
Numbers and strings - JavaScript | MDN
This chapter introduces the two most fundamental data types in JavaScript: numbers and strings. We will introduce their underlying representations, and functions used to work with and perform calculations on them.
🌐
GeeksforGeeks
geeksforgeeks.org › utilities › javascript-formatter
Online Free JavaScript Formatter and Beautifier - GeeksforGeeks
November 10, 2023 - Step 1. Input the JavaScript code in the first box. You can write the code, copy and paste it, or upload the JavaScript code file. Step 2. Click on the format button to format JavaScript code.
🌐
FreeFormatter
freeformatter.com › javascript-beautifier.html
Free Online Javascript Beautifier / Formatter - FreeFormatter.com
Formats JavaScript files with the chosen indentation level and your choice of braces. Supports 4 indentation levels: 2 spaces, 3 spaces, 4 spaces and tabs.
🌐
Code Beautify
codebeautify.org › jsviewer
Best Javascript Beautifier tool work as JavaScript Formatter, Viewer and Prettier
Often the javascript used is provided has white space compressed to reduce the size of the data transferred. This site give you a quick and easy way to format (beautifier) the javascript so you can easily read it.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Intl › NumberFormat › format
Intl.NumberFormat.prototype.format() - JavaScript | MDN
Use the format getter function for formatting all numbers in an array. Note that the function is bound to the Intl.NumberFormat from which it was obtained, so it can be passed directly to Array.prototype.map.
🌐
Format.JS
formatjs.github.io
Format.JS
A modular collection of JavaScript libraries focused on formatting numbers, dates, and strings.
Top answer
1 of 16
1662

Current JavaScript

From ES6 on you could use template strings:

let soMany = 10;
console.log(`This is ${soMany} times easier!`);
// "This is 10 times easier!"

See Kim's answer below for details.


Older answer

Try sprintf() for JavaScript.


If you really want to do a simple format method on your own, don’t do the replacements successively but do them simultaneously.

Because most of the other proposals that are mentioned fail when a replace string of previous replacement does also contain a format sequence like this:

"{0}{1}".format("{1}", "{0}")

Normally you would expect the output to be {1}{0} but the actual output is {1}{1}. So do a simultaneous replacement instead like in fearphage’s suggestion.

2 of 16
1512

Building on the previously suggested solutions:

// First, checks if it isn't implemented yet.
if (!String.prototype.format) {
  String.prototype.format = function() {
    var args = arguments;
    return this.replace(/{(\d+)}/g, function(match, number) { 
      return typeof args[number] != 'undefined'
        ? args[number]
        : match
      ;
    });
  };
}

"{0} is dead, but {1} is alive! {0} {2}".format("ASP", "ASP.NET")

outputs

ASP is dead, but ASP.NET is alive! ASP {2}


If you prefer not to modify String's prototype:

if (!String.format) {
  String.format = function(format) {
    var args = Array.prototype.slice.call(arguments, 1);
    return format.replace(/{(\d+)}/g, function(match, number) { 
      return typeof args[number] != 'undefined'
        ? args[number] 
        : match
      ;
    });
  };
}

Gives you the much more familiar:

String.format('{0} is dead, but {1} is alive! {0} {2}', 'ASP', 'ASP.NET');

with the same result:

ASP is dead, but ASP.NET is alive! ASP {2}

Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-string-formatting
JavaScript String Formatting - GeeksforGeeks
August 5, 2025 - Web Tutorial · A to Z Guide · ... : 5 Aug, 2025 · JavaScript string formatting refers to the technique of inserting variables, expressions, or values into strings to make them dynamic and readable....
🌐
YoungWonks
youngwonks.com › blog › javascript-string-format
JavaScript String Formatting: A Comprehensive Guide
September 28, 2023 - JavaScript, in web development, offers a variety of methods for string formatting. These methods make it easier to structure and manipulate text data in your applications. This tutorial aims to provide a comprehensive overview of JavaScript string format techniques, perfect for beginners and ...
🌐
JSON Formatter
jsonformatter.org › jsbeautifier
Best JSBeautifier to beautify / format JavaScript
This Javascript Beautifier that supports indentation levels: 2 tab spaces, 3 tab spaces, and 4 tab spaces. Download JS, once it's formatted, created or modified and this js file can be opened in Sublime, VSCode, and Notepad++ alternative.
🌐
EDUCBA
educba.com › home › software development › software development tutorials › javascript tutorial › javascript formatter
JavaScript formatter | How JavaScript formatter works with examples?
May 17, 2024 - Guide to JavaScript formatter. Here we discuss How JavaScript formatter works and Examples along with the codes and outputs.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
Numeraljs
numeraljs.com
Numeral.js
Set a default format so you can use .format() without a string.
🌐
Static.app
static.app › js-formatter
JS Formatter - Static.app
This ensures that your data remains confidential and secure throughout the formatting process. ... Paste or Upload Your JavaScript Code: Enter your JavaScript code directly into the formatter's text area or upload your JS file.
🌐
Biome
biomejs.dev
Biome, toolchain of the web
Try the Biome formatter on the playground or directly on your project: ... Biome is a performant linter for JavaScript, TypeScript, JSX, CSS and GraphQL that features 455 rules from ESLint, TypeScript ESLint, and other sources.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Intl › ListFormat › format
Intl.ListFormat.prototype.format() - JavaScript | MDN
An iterable object, such as an Array, containing strings. Omitting it results in formatting the empty array, which could be slightly confusing, so it is advisable to always explicitly pass a list.
🌐
Prettier
prettier.io
Prettier · Opinionated Code Formatter · Prettier
Your code is formatted on save · No need to discuss style in code review · Saves you time and energy · And more » · JavaScript · JSX · Flow · TypeScript · JSON · CSS · Less · SCSS · styled-components 💅 · styled-jsx · HTML · Vue · Angular · Ember / Handlebars ·
🌐
CodeShack
codeshack.io › home › tools › javascript formatter
JavaScript Formatter - Beautify and Format JS Code Online
Format and beautify your JavaScript code online. Paste messy JS or load a file, choose indentation, and get clean, readable code instantly.
🌐
Google
google.github.io › styleguide › jsguide.html
Google JavaScript Style Guide
Consider a future change that needs to touch just one line. This change may leave the formerly-pleasing formatting mangled, and that is allowed. More often it prompts the coder (perhaps you) to adjust whitespace on nearby lines as well, possibly triggering a cascading series of reformattings.