Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat does (+var) means
    text
    copied!<p>I'm new into the javascript world and I have not found any information about this notation. I found it in that topic (see the answer): <a href="https://stackoverflow.com/questions/9640266/convert-hhmmss-string-to-seconds-only-in-javascript">Convert HH:MM:SS string to seconds only in javascript</a>. </p> <pre><code>// minutes are worth 60 seconds. Hours are worth 60 minutes. var seconds = (+a[0]) * 60 * 60 + (+a[1]) * 60 + (+a[2]); </code></pre> <p>Also I wanted to use that code to convert 'HH:MM:SS' string to seconds. But, it seems unsafe for me. If the user inserts 'XX:03:SS', the value will be NaN which is not correct (at least for me). So I decided to improved it with: </p> <pre><code>function convertHHMMSSToSeconds(time) { // initialize seconds var seconds = 0; //ensure time if (!time) { return seconds; } try { var hmsTab = time.split(':'); // split it at the colons // ensure that the hmsTab contains 3 values (hh,mm,ss) if (!hmsTab || hmsTab.length !== 3) { return seconds; } // initialize hh, mm and ss var hh = hmsTab[0] &gt; 0 &amp;&amp; hmsTab[0] &lt; 60? +hmsTab[0] : 0; var mm = hmsTab[1] &gt; 0 &amp;&amp; hmsTab[1] &lt; 60 ? +hmsTab[1] : 0; var ss = hmsTab[2] &gt; 0 &amp;&amp; hmsTab[2] &lt; 60 ? +hmsTab[2] : 0; // return 0 if one variable is not valid if(+hmsTab[0] !== hh ||+hmsTab[1] !== mm || +hmsTab[2] !== ss) { return seconds; } // minutes are worth 60 seconds. Hours are worth 60 minutes. seconds = (hh * 60 * 60) + (mm * 60) + ss; }catch (error) { seconds = 0; } return seconds &amp;&amp; seconds&gt;0 ? seconds : 0; </code></pre> <p>}</p> <p>So my question still remains, what does (+var) mean.</p> <p>Regards,</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload