I have seen a syntax such as the following before:
var mynum = new Number();
var temp = (+mynum); //this line is what i am curious about
var text = temp.toPrecision(3);
Can anyone tell me what this + syntax means?
What I have found is that in some JS implementations, it is somehow necessary as it ensures that the number defined in mynum is valid.
Thanks,
jml
+is a unary operator which is used to coerce data types into numbers. Unary meaning it only needs one operand.new Datereturns an object, applying+coerces it into a timestamp eg1277504628812new Numberreturns an object, applying+coerces it into the numeric literal0.See: http://bclary.com/2004/11/07/#a-11.4.6
This is the ECMAScript documentation, which is the subset of Javascript, in HTML format.