new Array(width - this.length + 1).join(char)

This ^ is effectively saying "make an empty array with n number of slots, then join the empty slots together using the char to separate each empty slot. So, if char = "0", and n = 3, we get 000.

width - this.length + 1 is used to determine the number of characters needed to be added to beginning of the string.

Then we add that to the beginning of the original string: this

+1

You need the + 1 because of how join works.

new Array(1).join('0') = ""      // wrong
new Array(1+1).join('0') = "0"   // correct
new Array(2).join('0') = "0"     // wrong
new Array(2+1).join('0') = "00"  // correct
Answer from Kevin Jantzer on Stack Overflow
🌐
Mozilla
developer.mozilla.org › pt-BR › docs › Web › JavaScript › Reference › Global_Objects › Array › join
Array.prototype.join() - JavaScript | MDN
February 17, 2025 - O método join() junta todos os elementos de um array (ou um array-like object) em uma string e retorna esta string.
🌐
npm
npmjs.com › package › join-js
join-js - npm
October 9, 2020 - JoinJS is a JavaScript library to map complex database joins to nested objects.
      » npm install join-js
    
Published: Oct 09, 2020
Version: 1.1.2
🌐
YouTube
youtube.com › watch
JavaScript join Method Complete JS Array Methods Series - YouTube
In this tutorial we are goin to learn about the JavaScript join array method. This video is part of the Complete JavaScript Array Methods guide.💖 Support T...
Published: July 5, 2021
🌐
Codecademy
codecademy.com › docs › javascript › arrays › .join()
JavaScript | Arrays | .join() | Codecademy
October 8, 2022 - The .join() method returns a string representation of array elements concatenated together. ... Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
🌐
Execute Program
executeprogram.com › courses › javascript-array › lessons › join
Join Lesson - JavaScript Arrays
The JavaScript array "join" method combines an array's elements into a single string. We can customize the separator used between the array elements.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-array-join-method
JavaScript Array join() Method - GeeksforGeeks
January 16, 2026 - The JavaScript join() method is used to combine all elements of an array into a single string.
🌐
daily.dev
daily.dev › home › blog › webdev › join method javascript: faqs answered
Join Method JavaScript: FAQs Answered | daily.dev
May 25, 2026 - The join() method in JavaScript is like a glue for sticking all the pieces of an array together into one string.
🌐
freeCodeCamp
forum.freecodecamp.org › curriculum help
javaScript Array.join("") - Curriculum Help - The freeCodeCamp Forum
November 3, 2022 - The join() method creates and returns a new string by concatenating all of the elements in an array (or an array-like object), separated by commas or a specified separator string.
Top answer
1 of 4
9

What you're seeing is a tagged template literal, part of the ES6 specification. That pattern is heavily used in e.g. Google's Polymer Project (now lit-element). It invokes the supplied function (or in this case method) with the supplied template literal.

In addition to being used to create a Domain-Specific Language (DSL) of sorts, it's also frequently used to reduce the byte count for Javascript answers in code golf In the case of the Google project I linked, it's used as part of a domain-specific HTML templating language.

2 of 4
8

arr.join``; is a tagged template literal.

It applies join (or any other function) to "the content of the template literal string".

When I say "applies to the content of the template literal string" it is actually a little bit more complicated than that: all static parts of the string are put into an array as the first argument and the interpolated values as the remaining arguments.

A simple example will make it easier to understand:

var demo = (str, ...names) => {
  console.log(str);
  console.log(names);
};

var users = ['john', 'jane', 'joe'];

demo`Members: ${users[0]}, ${users[1]} and ${users[2]}.`;
// LOG: ["Members: ", ", ", " and ", "."]
// LOG: ["john", "jane", "joe"]

demo``;
// LOG: [""]
// LOG: []

The last line answers your question because arr.join``; is the same as arr.join(""); just two characters shorter which is useful when you compete in JS1K for example.

In this particular case I'm not sure that the author wanted to save a few bytes because we can shorten the initial statement as follow:

new Array(10).fill('1').join``;
new Array(10).fill(1).join``;
Array(10).fill(1).join``;
'1'.repeat(10);
'1111111111';

Is a tagged template just a glorified function call?

These two expressions may look similar but they are not:

var yy = 20;
year`19${yy}`;
year(`19${yy}`);

In the first expression we have access to the static and dynamic parts of the string: "19" and 20. In the second expression we only get the "final" string "1920".

This is useful when one wants to preserve intent yet allow complex text processing behind the scene.

We know that this is unsafe:

var sql = `SELECT * FROM users where email="${email}" AND password="${password}"`;

To mitigate the risk of SQL injection, it is not uncommon to see things like:

var sql = select('*').from('users').where('AND').eq('email', email).eq('password', password);

However it could be argued that we have traded the expressiveness of SQL with a somewhat awkward API that people are less likely to be familiar with.

If a tagged template literal has access to both static and dynamic parts of a string we can build domain-specific tagged template literals:

var sql = safe_sql`SELECT * FROM users where email="${email}" AND password="${password}"`;
🌐
Programiz
programiz.com › javascript › library › array › join
Javascript Array join() | Programiz
March 4, 2024 - The join() method returns a new string by concatenating all of the elements in an array, separated by a specified separator. let message = ["JavaScript", "is", "fun."]; // join all elements of array using space let joinedMessage = message.join(" ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › concat
Array.prototype.concat() - JavaScript | MDN
4 days ago - The concat() method of Array instances is used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array.
🌐
YouTube
youtube.com › watch
Array 'join' method in Javascript (Array.prototype.join) - YouTube
By using the 'join' method, you are able to convert an Array into a String, formatted the way you like. This is done using a separator and it is common to se...
Published: December 27, 2017
🌐
ReqBin
reqbin.com › code › javascript › 98ugueow › javascript-array-join-example
How do I join array elements in JavaScript?
To join JavaScript array elements in a string, you can use the array.join(separator) method. The array.join() method takes an array as input and a delimiter as a parameter and returns a string where all array elements are joined into a string ...
🌐
DEV Community
dev.to › shubhamtiwari909 › join-in-javascript-4050
Array Methods in JS - join() - DEV Community
August 21, 2022 - I would say that phrase - "join method in javascript" is not a correct one. Method is a function which is combined with an object. Join() is a method of Array.prototype object.