1

Found some code which implements the Date.now function for older browsers, code is

Date.now=Date.now||function(){return+(new Date)};

what does the + operator do ? cant find anything on the net

john Smith
  • 15,471
  • 10
  • 66
  • 107

2 Answers2

2

From the doc:

Unary plus (+)

The unary plus operator precedes its operand and evaluates to its operand but attempts to converts it into a number, if it isn't already. Although unary negation (-) also can convert non-numbers, unary plus is the fastest and preferred way of converting something into a number, because it does not perform any other operations on the number. It can convert string representations of integers and floats, as well as the non-string values true, false, and null. Integers in both decimal and hexadecimal ("0x"-prefixed) formats are supported. Negative numbers are supported (though not for hex). If it cannot parse a particular value, it will evaluate to NaN.

Syntax

Operator: +x

Examples

+3     // 3
+"3"   // 3
+true  // 1
+false // 0
+null  // 0

References

Arithmetic operators

Alex Char
  • 31,748
  • 8
  • 48
  • 67
0

You are converting the Date object into an integer. It represents the number of miliseconds since 1/1/1970