Convert string to integer in Javascript

var s = "1337";
alert(parseInt(s) * 2);

Time Javascript operations

Sometimes I need to time how long a Javascript operation takes. It’s very easy if you are using jQuery.

   console.time("longOperation");
   for (var i=0; i<1000; ++i){ var j = i*i; } //do something complicated
   console.timeEnd("longOperation");

Then, you’ll see the result in the Firebug console:
Time Javascript operations