Odd javascript syntax: c.name = i + + new date;

colorbox v1.3.15 from colorpowered.com has this javascript abbreviated code in it:

c.name=i+ +new Date;

It seems to work fine, right?

+5
source share
2 answers

The unary operator is +used to convert an object to a number, calling valueOf()from this object. If the number is not returned, the operation returnsNaN

You can customize this by editing the function valueOffor any object, for example:

var foo = {};
foo.valueOf = function () { return 9001; };
console.log(+foo); // 9001

Date valueOf()just returns getTime()( according to Mozilla )

+8
source

new Date Date . unary + , Date getTime(). , i .

+5

All Articles