Is string with a value of "Error" some sort of reserved word?

117 views Asked by At

So I have a following line of Javascript on my page:

form.display.value = 'Error';

where display is an input of type text on my page:

<input type="text" id="calcDisplay" name="display" maxlength="25">

in Chrome this works just fine making the value of the input element to be "Error". But in IE 10 and Firefox the content of the input is the following:

function Error() {    [native code]}

Can anyone explain what is going on here and why?

UPDATE: This is the actual function being called:

function compute(form) {
   try {
      form.display.value = eval(form.display.value);
   } catch(e) {
      form.display.value = 'Error';
   } 
}

And here is the video of it so you guys don't think that I'm crazy:

http://screencast.com/t/sq9xXrnf

1

There are 1 answers

2
Jacob On BEST ANSWER

When the value Error is already in the input, this line:

form.display.value = eval(form.display.value);

...is going to evaluate to the function Error you defined earlier. So this must be happening on a second call to your compute function.

Note that browsers are inconsistent with how eval works, which is why you see browser differences.