I'm new to Javascript, and I am using d3.js for visualizations. I know about operator meanings and concatenation, and have read that the +
sign can perform changing the right-hand operand to the +
sign to a numeric value, however I'm stumped on what the line gravity = +x;
in force.gravity
is doing since x is already a numeric value (already an integer). I have tested with negative and positive numbers and it seems to just return the value I pass through the x
, I do get past the if statement for my uses. Whereas, if I use -x
then it will change the sign. Can anyone explain what is going on with the +
&-
and why the function is basically just returning what I pass.
force.gravity = function(x) {
if (!arguments.length) return gravity;
gravity = +x;
return force;
};