In jquery source:
eq: function( i ) {
i = +i;
return i === -1 ?
this.slice( i ) :
this.slice( i, i + 1 );
},
Is it used for make sure parse i to int?
Is it used for make sure parse i to int?
No, it is to make sure that i is a number (either float or int). Given what the function is doing, it was better to convert i to an non-decimal value though, I'm not sure how slice handles decimals.
More information: MDN - Arithmetic Operators
Almost, but any number is fine.
[ECMA-262: 11.4.6]:The unary+operator converts its operand toNumbertype.The production UnaryExpression : + UnaryExpression is evaluated as follows:
- Let expr be the result of evaluating UnaryExpression.
- Return ToNumber(GetValue(expr)).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With