Note that there are some explanatory texts on larger screens.

plurals
  1. PODo older versions of javascript evaluate ("-1" < 0) as false?
    primarykey
    data
    text
    <p>A bit of js on my brother's eCommerce site computes and stores transaction totals every time someone checks out. Periodically, a negative value is stored for tracker_total_amount. While he tries to work out why, he's decided to hard code an override which should address the ~0.1% of transactions with nonsensical values. It looks like this:</p> <pre><code>var tracker_total_amount = parseFloat(tracker.total_amount).toFixed(2); if(tracker_total_amount &lt; 0){ tracker_total_amount = 0; } </code></pre> <p>Negative values have continued to show up in the system.</p> <p>Original theory:</p> <p>I don't think he should be using .toFixed, because that's going to cast tracker_total_amount as a string - which, in my mind, would have stopped the if &lt; 0 condition working as expected. I was quite happy with this explanation until I tested it and the override worked. See here: <a href="http://jsfiddle.net/yXTrz/" rel="nofollow noreferrer">http://jsfiddle.net/yXTrz/</a></p> <p>New theory:</p> <p>Different users are running different versions of javascript. Some very small subset use an ancient version of javascript which (instead of helpfully converting the string to a float like mine is doing) continue to treat it as a string and always evaluate tracker_total_amount as being > 0, preventing the override from firing.</p> <p>Question:</p> <p>Did older version of javascript behave in this way? Could some users still be running those old versions? Best of all - is there a way I can simulate legacy versions of javascript to prove my theory?</p> <p>Edit: I should point out all the important stuff (payment etc) relies on a server side calculated value. The numbers here are just what's stored in Google Analytics afterwards, so - while it's possible to manipulate - the results wouldn't be too atrocious.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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