Why can this js code be output?

Why can this js code output a? What do two dots mean?

Object.prototype.a = "a";
console.log(1..a) // a
Jul.18,2022

your question is equivalent to: 1..toString () Why can it be executed while 1.toString () cannot?

for numbers, 1. is parsed as a number, so to call the number method, we can use 1..toString () , or we can use (1). ToString () , (1.). ToString ().

therefore, for your example, it is equivalent to console.log ((1) .a), and of course you can output it.


1.===1//true

Menu