Just saw this in underscore's source:
if (obj.length === +obj.length) {
...
}
What does the plus
do? I never saw this before.
Is it considered a good practice among developers?
Just saw this in underscore's source:
if (obj.length === +obj.length) {
...
}
What does the plus
do? I never saw this before.
Is it considered a good practice among developers?
The plus converts a string to a float. The code you provided is equivalent to the following:
if ( obj.length === Number(obj.length) ) {
// ...
}