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
  • 8,592
  • 29
  • 109
  • 204

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
  • 111,938
  • 35
  • 201
  • 280