JS error "re-declaration" var when the first line in the program?

SCRPT5039: Redeclaration of const property line 1 character 1

line1: var editObj = null;

This is the beginning of the file, and I checked that the variable is not contained in any other js files. Is this a statement that I will recycle it later? (if so, that the link to the string is not useful) or what is wrong with this?

+8
javascript constants
source share
6 answers

EDIT: Fixed. For me, anyway. I got this error before the re-allocation error:

 HTML1113: Document mode restart from Quirks to IE9 Standards 

This suggests that IE detects what it considers to be an error, so it loads the page again in Quirks mode. Loading a page twice makes you think that everything is declared twice. So the solution is to find what IE didn't like.

First, I launched the page through an online HTML check . Then I ran javascript through jsLint . After all this, IE9 seemed happy. And as a bonus, I have the best quality code. I hope so.

+3
source share

I got this error with the following code:

 var window; 

I added this declaration to bypass the node error when using the following code:

 if (!window) { //node-specific stuff } 

Without the above declaration, node wold complains. In the end, I decided to copy / paste, rather than trying to use the same file between node and browser implementations.

+5
source share

I had a similar problem with the same error, but my first line of code was alert(0); I inserted to make sure the script is loaded! Interestingly, the script was loaded in accordance with the IE9 developer tools, but the first line was never executed, and the error indicated alert(0); as a re-declaration. I even inserted lines and spaces in front of them, and changed the line and character number accordingly. However, this (obviously) was not what was remodeled, because it is not even a declaration, not to mention a re-declaration!

I removed the pieces from the end of the script until I ran alert(0); (indicating that the script was loaded and successfully processed), and I found that the violation line is:

 var screen; 

It turns out that IE9 already has window.screen that this ad came across, and renaming my screen to eScreen fixed the problem.

So my answer is: do not trust IE9's direction about where the re-announcement happens!

(It is also worth noting that the script works fine in its original form on IE7, IE8, and IE10, not IE9.)

+3
source share

I had the same problem in my code, and it turned out that IE was displaying the wrong line as re-entry appears. In my case, it was a story that I use later in the code. You must check all the code to redefine constants. You can try to comment on a part of the code and see when it throws this error.

+1
source share

The error occurs because you declared some global / local variable that corresponds to the default property of the browser. Something like

 var window = ''; var navigator = ''; 

Try deleting or commenting on such an ad and see the effects.

+1
source share

I had the same error and stumbled upon this post. Although I did not have the same root problem as the OP, I thought I would share my solution if others make my mistake and come here. I got the error in a separate js file. After simplifying it, I found that I could generate an error from the following code:

 var foo = null; var bar = null; var localData = null; 

The error indicated that it was the first line. However, foo was not updated. The problem was that localData might have been used elsewhere (not in my code). No matter how far the localData file has been declared, the error is listed as the first line of the line.

So, if other solutions do not work, try renaming each variable in the code file to determine which one may cause the problem. Do not believe the debugger points to the correct line.

Discovered: HTML5 / JS Window Store application.

0
source share

All Articles