Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remainder/Modulus of string is a number

Why is this even possible?

console.log('13' % 2);

1

I assume JavaScript just converts the string on its own. I would appreciate any info on this behaviour.

like image 324
Tomasz Szymanek Avatar asked Sep 05 '25 03:09

Tomasz Szymanek


1 Answers

As a starting point: http://ecma-international.org/ecma-262/5.1/#sec-11.5

The ToNumber operation is performed on the left argument (which results in the left argument being treated as the number, as explained in http://ecma-international.org/ecma-262/5.1/#sec-9.3.1)

like image 101
SheetJS Avatar answered Sep 07 '25 19:09

SheetJS