What is the purpose of a plus symbol before a variable?

javascript

Solution

The `+` operator returns the numeric representation of the object. So in your particular case, it would appear to be predicating the if on whether or not `d` is a non-zero number.

Reference here. And, as pointed out in comments, here.

Problem

What does the `+d` in ``` function addMonths(d, n, keepTime) { if (+d) { ``` mean?

Original source

Related problems