Unary Plus Operator (+)

By: Dusty Arlia
Published on Monday, March 18, 2013, 08:41 AM
Last Updated on Friday, July 17, 2015 at 3:29 PM
Total Updates: 4

The unary plus operator (+) is a unary operator that converts the operand's data type to a number if it isn't one already. If it is a number already, then it doesn't do anything. If it is a string that cannot be converted to a number, then the expression evaluates to NaN. Using the unary plus operator is the same as using the Number() function. Here's an example:

x = "3";    //The x variable has a value of a string "3"
y = +x;   //The y variable has a value of a number 3

The unary plus operator (+) forced the number data type conversion.

Comments:

Ad:

Ad: