javascript - plus signs in the JS code - why aren't they optional here -


i'm curious answer taken dagg nabbit @ so here: convert hh:mm:ss string seconds 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 expected - doesn't calculate number of seconds. why?

they cause implicit conversion of string number. in browser's debug console, try:

> typeof +'1' "number" > typeof '1' "string" 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -