Looking through the jQuery source in the function now() I see the following:
function now(){
return +new Date;
}
I’ve never seen the plus operator prepended to the new operator like this. What does it do?
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.
Nicolás and Brian are right, but if you’re curious about how it works,
+new Date();is equivalent to(new Date()).valueOf();, because the unary+operator gets the value of its operand expression, and then converts itToNumber.You could add a
valueOfmethod on any object and use the unary + operator to return a numeric representation of your object, e.g.: