0

When one uses, for example, $(this).val() on an input field event handler, one gets a string. But, if one uses +$(this).val(), one gets the corresponding number. Is this a feature from Javascript or jQuery? Is +$ another function, different from $, or is it an operator on the $ function?

rvcam
  • 147
  • 5
  • 15
  • 2
    it is the [unary plus operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Unary_plus_(.2B)) – Arun P Johny Aug 19 '14 at 02:44
  • http://stackoverflow.com/questions/17106681/parseint-vs-unary-plus-when-to-use-which – Arun P Johny Aug 19 '14 at 02:44
  • It's a `unary plus` operator in javascript which converts the other types to `Number` type if possible. But if it can't it will return `NaN`. – Mritunjay Aug 19 '14 at 02:46
  • It is indeed a duplicate. But I think I shouldn't delete it, because, as I couldn't find that question, someone might find this question instead of the other one. What should I do? – rvcam Aug 19 '14 at 02:49
  • FYI, jQuery is just a library. It does not add any new syntax or operators or extends JavaScript in any way. If it did, you'd need a preprocessor that converts the code to JavaScript the browser can understand. – Felix Kling Aug 19 '14 at 02:49
  • @FelixKling yeah, but I was suspecting that +$ was a function of that library, because I didn't check and see that +$ isn't a valid identifier – rvcam Aug 19 '14 at 02:52

0 Answers0