0

Seen the following snippet on https://nuxtjs.org/api/pages-transition

export default {
  transition (to, from) {
    if (!from) return 'slide-left'
    return +to.query.page < +from.query.page ? 'slide-right' : 'slide-left'
  }
}

I wonder what the + before the variable is?

Daniel W.
  • 31,164
  • 13
  • 93
  • 151
  • It's a concise way of coercing something that might not be a number, to a number. So `+"22"` is the number value `22`. – Pointy Apr 10 '19 at 13:29
  • So a short form of `.parseInt()`? – Daniel W. Apr 10 '19 at 13:31
  • 1
    Well a short form of `Number(something)` — it's *like* `parseFloat(something)` except that `parseFloat()` allows non-numeric text after the number in a string, so the string `"123.45hello"` would be OK with `parseFloat()` but `NaN` with `Number()` (or the `+` operator) – Pointy Apr 10 '19 at 13:42

0 Answers0