jQuery’s .eq() is:
eq: function( i ) {
return i === -1 ?
this.slice( i ) :
this.slice( i, +i + 1 );
},
What is the point of the first + in +i + 1?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s to cast the value to integer and to ensure that you are performing an integer addition instead of string concatenation.
Compare those two for example:
And to answer the question why this is not used as the first argument of the slice method, it is because the slice method internally performs the conversion. So for example the following will work as expected: