2

What is the application of the plus operator in these cases? I have seen it used in these ways but don't see how it operates.

start = +new Date;

+array[i]

+f.call(array, array[i], i)

x = +y
1

1 Answer 1

9

+ will implicitly cast a string / boolean value into a Number().

+"66" === 66

If the string cannot be converted into a Number, the value will be NaN

+"not possible" // evaluates to NaN

In the case of a Date() object, + will also cast the data into its numerical representation, that is the UNIX timestamp.

So, finally spoken, leading an expression with + is pretty much the same as explicitly wrapping the Number() constructor around it:

+new Date()

equals

Number( new Date() )
Sign up to request clarification or add additional context in comments.

1 Comment

or any primitive value into a number for that matter...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.