Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript odd syntax: c.name=i+ +new Date;

Tags:

javascript

colorbox v1.3.15 from colorpowered.com has this javascript in it's minified code:

c.name=i+ +new Date;

this seems to run perfectly, should it?

like image 262
Myster Avatar asked Mar 10 '11 02:03

Myster


People also ask

What is the format of new Date ()?

By default, when you run new Date() in your terminal, it uses your browser's time zone and displays the date as a full text string, like Fri Jul 02 2021 12:44:45 GMT+0100 (British Summer Time).

What is ?: In JavaScript?

The conditional (ternary) operator is the only JavaScript operator that takes three operands: a condition followed by a question mark ( ? ), then an expression to execute if the condition is truthy followed by a colon ( : ), and finally the expression to execute if the condition is falsy.

What is new syntax in JavaScript?

New keyword in JavaScript is used to create an instance of an object that has a constructor function. On calling the constructor function with 'new' operator, the following actions are taken: A new empty object is created.

What is the correct JavaScript syntax for opening a new?

The open() method opens a new browser window, or a new tab, depending on your browser settings and the parameter values.


1 Answers

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

You can customize this by editing the valueOf function for any object, like so:

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

Date's valueOf() simply returns getTime() (according to Mozilla)

like image 131
Matt Avatar answered Nov 11 '22 09:11

Matt