Re: how to use a static variable?

Tech-Archive recommends: Fix windows errors by optimizing your registry



JRS: In article <OtX#ZIsjFHA.476@xxxxxxxxxxxxxxxxxxxx>, dated Fri, 22
Jul 2005 15:29:18, seen in news:microsoft.public.scripting.jscript,
Chris <rrr@xxxx> posted :

>tempsreel= new Date()
>trh=tempsreel.getHours()
>trm=tempsreel.getMinutes()
>trs=tempsreel.getSeconds()
>te=parseInt(trh)*3600+parseInt(trm)*60+parseInt(trs)

Other things apart, those parseInt calls are worse than useless.
Variables trh trm trs are set, by those .get calls, to Numbers. The
arguments are then converted to strings for parseInt, which converts
them back. Use

te = (trh*60+trm)*60+trs ;

When use of parseInt is actually justified, then one should consider
whether it needs a second parameter; it will do so if there is any risk
of leading zeroes in the strings provided. Unless in the string there
are other characters following the number part, ISTM better to use a
unary + for string-to-integer conversion : I = + S ; .

See sig below.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
.



Relevant Pages

  • Re: is there a JS equivelent
    ... I sorta suspected parseInt() could have some issues, ... to strings prior to parsing those strings. ... programming language to state what it is that feature does in that other ...
    (comp.lang.javascript)
  • Re: is there a JS equivelent
    ... floorand ceil() are nice functions, ... but neither of them are equivialent to int. ... parseInt() is a better choice. ... Because it converts numeric arguments to strings and then parses those ...
    (comp.lang.javascript)
  • Re: how to use a static variable?
    ... those parseInt calls are worse than useless. ... > Variables trh trm trs are set, by those .get calls, to Numbers. ... > of leading zeroes in the strings provided. ... > TP/BP/Delphi/jscr/&c, FAQ items, ...
    (microsoft.public.scripting.jscript)
  • Question about Number / parseInt ..and octals
    ... parseInt considers.. ... '0x'-prefixed strings as hexadecimal ... when using the Number constructor ... mynum = Number ...
    (microsoft.public.scripting.jscript)