I'm starting with some modern Javascript, I decided to use Nodejs, because at the moment it is the most popular structure for JS on the desktop, I don’t understand why my code is not working and the related error message I get.
Consider this snippet
var a = 5;
var func = function(){return arguments.length;};
process.stdout.write(+func(1,2,3,a));
It does not work and generates the following error message
net.js:612
throw new TypeError('invalid data');
^
TypeError: invalid data
at WriteStream.Socket.write (net.js:612:11)
at Object.<anonymous> (var_1.js:3:16)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:902:3
I am a C / C ++ programmer, and for me this is absolutely mysterious, moreover, I used it +before the call functo make sure the result integer, so why writecomplain about everyone?
After some nonsense adding + '\n', this code works
var a = 5;
var func = function(){return arguments.length;};
process.stdout.write(+func(1,2,3,a) + '\n');
Can anyone explain what is happening?