How to chain a method to a number literal

How to chain a method to a number literal

SyntaxError: identifier starts immediately after numeric literal

Feb 10, 2022Β·

1 min read

In JavaScript, you can chain a method to a string literal.

Example using .toLowerCase method:

const sentence = "A cool sentence".toLowerCase();


But this will not work with a number literal, example using .toString:


Depending on the runtime you can get different error messages, for Example in Deno you get:

parse error: Identifier cannot follow number

How to "fix it"?

You can easily overcome this


This looks a little weird but will work too


This one works too!

console.log(458 .toString());

Note the space

Real word example

You want to get the exponential of a number using toExponential πŸ‘‡

console.log(1_000_000 .toExponential()); //=> '1e+6'