JavaScript logoJavaScript/
JS-0065

Found leading or trailing decimal points in numeric literalsJS-0065

Minor severityMinor
Anti-pattern categoryAnti-pattern

Float values in JavaScript contain a decimal point, and there is no requirement that the decimal point be preceded or followed by a number. For example, the following are all valid JavaScript numbers:

let num = .5;
num = 2.;
num = -.7;

Although not a syntax error, this format for numbers can make it difficult to distinguish between true decimal numbers and the dot operator. For this reason, some recommend that you should always include a number before and after a decimal point to make it clear the intent is to create a decimal number.

Bad Practice

let num = .5;
num = 2.;
num = -.7;
let num = 0.5;
num = 2.0;
num = -0.7;