0

I'm curious about the answer that was taken by Dagg Nabbit at SO here: Convert HH:MM:SS string to seconds only in javascript

var seconds = (+a[0]) * 60 * 60 + (+a[1]) * 60 + (+a[2]); 

Right,

var seconds = (a[0]) * 60 * 60 + (a[1]) * 60 + (a[2]); 

doesnt work as expected - it doesn't calculate the number of seconds. Why?

Community
  • 1
  • 1
Haradzieniec
  • 9,086
  • 31
  • 117
  • 212

1 Answers1

4

They cause an implicit conversion of a string into a number. In your browser's debug console, try:

> typeof +'1'
"number"
> typeof '1'
"string"
Daniel Earwicker
  • 114,894
  • 38
  • 205
  • 284