Doc states mode argument should be an integer. However, in the tests, this argument is sometimes intentionally cast to string. In fs lib, this function is used for string supporting.
What is going on here? :)
Octal string (e.g. '755') support was added back in 2011 (specifically https://github.com/nodejs/node/commit/5f2e90934e523b2fe102e3e5bae3ea76535ab8b5) as a way to avoid the need for calling parseInt() in user code because at that time octal representation (e.g. 0755) is/was not allowed in strict mode.
Nowadays this is no longer an issue since with ES6 we now have a new octal representation (e.g. 0o755) that can be used in either mode because the new octal format is no longer ambiguous.
As to why it's explicitly cast to a string, who knows. Perhaps to test the acceptance of strings?
So the doc better be left as is?
For the specific test you linked to, you can see that a string literal was originally used before a number converted to string was used.
I think the docs are probably fine as-is since I don't think we want to start encouraging (by documenting) the use of strings since ES6 octal representation has been around for awhile now. *shrug*
Thank you!
Most helpful comment
I think the docs are probably fine as-is since I don't think we want to start encouraging (by documenting) the use of strings since ES6 octal representation has been around for awhile now. *shrug*