Skip to main content
Commonmark migration
Source Link

##Using .padEnd() instead of .repeat() (ES8)

Using .padEnd() instead of .repeat() (ES8)

Under certain circumstances, using .padEnd() instead of .repeat() saves bytes.

We can take advantage of the following properties:

  • the default padding string is a single space
  • when provided, the second parameter is implicitly coerced to a string

###Repeating spaces

Repeating spaces

With .repeat():

' '.repeat(10)

Using .padEnd() saves 1 byte:

''.padEnd(10)

Try it online!

###Repeating a dynamic value that needs to be coerced to a string

Repeating a dynamic value that needs to be coerced to a string

With .repeat():

x=1;
(x+'').repeat(10)

Using .padEnd() saves 2 bytes:

x=1;
''.padEnd(10,x)

Try it online!

##Using .padEnd() instead of .repeat() (ES8)

Under certain circumstances, using .padEnd() instead of .repeat() saves bytes.

We can take advantage of the following properties:

  • the default padding string is a single space
  • when provided, the second parameter is implicitly coerced to a string

###Repeating spaces

With .repeat():

' '.repeat(10)

Using .padEnd() saves 1 byte:

''.padEnd(10)

Try it online!

###Repeating a dynamic value that needs to be coerced to a string

With .repeat():

x=1;
(x+'').repeat(10)

Using .padEnd() saves 2 bytes:

x=1;
''.padEnd(10,x)

Try it online!

Using .padEnd() instead of .repeat() (ES8)

Under certain circumstances, using .padEnd() instead of .repeat() saves bytes.

We can take advantage of the following properties:

  • the default padding string is a single space
  • when provided, the second parameter is implicitly coerced to a string

Repeating spaces

With .repeat():

' '.repeat(10)

Using .padEnd() saves 1 byte:

''.padEnd(10)

Try it online!

Repeating a dynamic value that needs to be coerced to a string

With .repeat():

x=1;
(x+'').repeat(10)

Using .padEnd() saves 2 bytes:

x=1;
''.padEnd(10,x)

Try it online!

added 3 characters in body
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650

##Using .padEnd() instead of .repeat() (ES8)

Under certain circumstances, using .padEnd() instead of .repeat() saves bytes.

We can take advantage of the following properties:

  • the default padding characterstring is a single space
  • when provided, the padding charactersecond parameter is implicitly coerced to a string

###Repeating spaces

With .repeat():

' '.repeat(10)

Using .padEnd() saves 1 byte:

''.padEnd(10)

Try it online!

###Repeating a dynamic value that needs to be coerced to a string

With .repeat():

x=1;
(x+'').repeat(10)

Using .padEnd() saves 2 bytes:

x=1;
''.padEnd(10,x)

Try it online!

##Using .padEnd() instead of .repeat() (ES8)

Under certain circumstances, using .padEnd() instead of .repeat() saves bytes.

We can take advantage of the following properties:

  • the default padding character is a space
  • when provided, the padding character is implicitly coerced to a string

###Repeating spaces

With .repeat():

' '.repeat(10)

Using .padEnd() saves 1 byte:

''.padEnd(10)

Try it online!

###Repeating a dynamic value that needs to be coerced to a string

With .repeat():

x=1;
(x+'').repeat(10)

Using .padEnd() saves 2 bytes:

x=1;
''.padEnd(10,x)

Try it online!

##Using .padEnd() instead of .repeat() (ES8)

Under certain circumstances, using .padEnd() instead of .repeat() saves bytes.

We can take advantage of the following properties:

  • the default padding string is a single space
  • when provided, the second parameter is implicitly coerced to a string

###Repeating spaces

With .repeat():

' '.repeat(10)

Using .padEnd() saves 1 byte:

''.padEnd(10)

Try it online!

###Repeating a dynamic value that needs to be coerced to a string

With .repeat():

x=1;
(x+'').repeat(10)

Using .padEnd() saves 2 bytes:

x=1;
''.padEnd(10,x)

Try it online!

minor update
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650

##[ES8] Using##Using .padEnd() instead of .repeat() (ES8)

There are severalUnder certain circumstances under which, using .padEnd().padEnd() instead of .repeat() savesaves bytes.

We can take advantage of the following properties:

  • the default padding character is a space
  • when provided, the padding character is implicitly coerced to a string

###Repeating spaces

With .repeat():

' '.repeat(10)

Using .padEnd() saves 1 byte:

''.padEnd(10)

Try it online!

###Repeating a dynamic value that needs to be coerced to a string

With .repeat():

x=1;
(x+'').repeat(10)

Using .padEnd() saves 2 bytes:

x=1;
''.padEnd(10,x)

Try it online!

##[ES8] Using .padEnd() instead of .repeat()

There are several circumstances under which using .padEnd() instead of .repeat() save bytes.

###Repeating spaces

With .repeat():

' '.repeat(10)

Using .padEnd() saves 1 byte:

''.padEnd(10)

Try it online!

###Repeating a value that needs to be coerced to a string

With .repeat():

x=1;
(x+'').repeat(10)

Using .padEnd() saves 2 bytes:

x=1;
''.padEnd(10,x)

Try it online!

##Using .padEnd() instead of .repeat() (ES8)

Under certain circumstances, using .padEnd() instead of .repeat() saves bytes.

We can take advantage of the following properties:

  • the default padding character is a space
  • when provided, the padding character is implicitly coerced to a string

###Repeating spaces

With .repeat():

' '.repeat(10)

Using .padEnd() saves 1 byte:

''.padEnd(10)

Try it online!

###Repeating a dynamic value that needs to be coerced to a string

With .repeat():

x=1;
(x+'').repeat(10)

Using .padEnd() saves 2 bytes:

x=1;
''.padEnd(10,x)

Try it online!

Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650
Loading