1function smallestFactor(x) {
2 for (i = 2; i <= Math.floor(x**.5); i++) { 3 if (x % i == 0) {
4 return i;
5 };
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.
let num = .5;
num = 2.;
num = -.7;
let num = 0.5;
num = 2.0;
num = -0.7;