Javascript Sintax Errors

1002 Syntax error

You created a statement that violates one or more of the grammatical rules of JScript.

To correct this error

  • Double-check the syntax of your program on the line number indicated.
  • Look for misdirected parentheses or braces.
1003 Expected ':'

You attempted to create an expression using the ternary conditional operator, but did not include the colon between the second and third operands. The ternary (three operands) conditional operator requires a colon between the second (true) and third (false) operands.

To correct this error

Insert a colon between the second and third operands.

1004 Expected ';'

You attempted to place more than one statement on a line, but did not separate them with semicolons. Semicolons are used to terminate statements. Although you can place several statements on a single line, each one must be delimited from the next with a semicolon.

To correct this error

  • Mark the end of each statement with a semicolon.
  • Make sure your function calls use parentheses properly.
  • Make sure you did not forget the semicolons inside the header of a for loop.
1005 Expected '('

You attempted to enclose an expression within a set of parentheses, but did not include the opening parenthesis. Some expressions must be enclosed within a set of opening and closing parentheses. Notice the use of parentheses in the following example.

for (initialize; test; increment) {
statement;
}

To correct this error

  • Add the left parenthesis to the evaluation expression.

 

1006 Expected ')'

You attempted to enclose an expression within a set of parentheses, but did not include the closing parenthesis. Some expression must be enclosed within a set of opening and closing parentheses. Notice the use of parentheses in the following example.

for (initialize; test; increment) {
statement;
}

To correct this error

  • Add the right parentheses to the evaluation expression.
1007 Expected ']'

You made a reference to an array element, but did not include the right bracket. Any expression that refers to an array element must include both opening and closing brackets.

To correct this error

Add the right bracket to the expression that refers to the array element.

1008 Expected '{'

You attempted to enclose an expression within a set of parentheses, but did not include the opening parenthesis. Some expressions must be enclosed within a set of opening and closing parentheses. Notice the use of parentheses in the following example.

for (initialize; test; increment) {
statement;
}

To correct this error

  • Add the left parenthesis to the evaluation expression.
1009 Expected '}'

You did not include the right brace that marks the end of the function body, loop, block of code, or object initializer. An example of this error would be a for loop with only the left brace marking the body of the loop.

To correct this error

Add the right brace that marks the ending of the function, loop, block, or object initializer.

1010 Expected identifier

You used something other than an identifier in a context where one was required. An identifier can be:

  • a variable,
  • a property,
  • an array,
  • or a function name.

To correct this error

Change the expression so an identifier appears to the left of the equal sign.

1011 Expected '='

You attempted to create a variable to be used with conditional compilation statements, but did not place an equal sign between the variable and the value you want to assign to it.

To correct this error

Add an equal sign. For example:

@set @myvar1 = 1
1012 Expected '/'

You attempted to create a regular expression literal, but did not include one of the slashes (/). Just as string literals are written as characters within a pair of quotation marks, regular expression literals are expressed as characters within a pair of slash (/) characters.

To correct this error

Insert a terminating forward slash to mark the end of the regular expression.

1014 Invalid character

You composed an identifier using a character (or characters) not recognized as valid by the JScript compiler. Valid characters use the following rules:

  • The first character must be an ASCII letter (either uppercase or lowercase) or an underscore (_).
  • Subsequent characters can be ASCII letters, numbers, or underscores.
  • The identifier name cannot be a reserved word.

To correct this error

Avoid using characters that are not part of the JScript language definition.

1015 Unterminated string constant

You did not end your string constant with a closing quotation mark. String constants must be enclosed within a pair of quotation marks.

Note   You can use matching pairs of single or double quotation marks. Double quotation marks can be contained within strings surrounded by single quotation marks, and single quotation marks can be contained within strings surrounded by double quotation marks.

To correct this error

Add the closing quotation mark to the end of the string.

1016 Unterminated comment

You began a multi-line comment block, but did not properly terminate it. Multi-line comments begin with a "/*" combination, and end with the reverse "*/" combination. The following is an example:

/* This is a comment
This is another part of the same comment.*/

To correct this error

Be sure to terminate multi-line comments with "*/".

1018 'return' statement outside of function

You used a return statement in the global scope of your code. The return statement should only appear within the body of a function.

Invoking a function with the () operator is an expression. All expressions have values; the return statement is used to specify the value retuned by a function. The general form is:

return [ expression ];

When the return statement is executed, expression is evaluated and returned as the value of the function. If there is no expression, undefined is returned.

Execution of the function stops when the return statement is executed, even if there are other statements still remaining in the function body. The exception to this rule is if the return statement occurs within a try block, and there is a corresponding finally block, the code in the finally block will execute before the function returns.

If a function returns because it reaches the end of the function body without executing a return statement, the value returned is the undefined value (this means the function result cannot be used as part of a larger expression).

To correct this error

Remove the return statement from the main body of your code (the global scope).

1019 Can't have 'break' outside of loop

You attempted to use the break keyword outside of a loop. The break keyword is used to terminate a loop or switch statement. It must be embedded in the body of a loop or switch statement.

Exception

A label can follow the break keyword.

break labelname;

You only need the labeled form of the break keyword when you are using nested loops or switch statements and need to break out of a loop that is not the innermost one.

To correct this error

Make sure the break keyword appears inside an enclosing loop or switch statement.

 

1020 Can't have 'continue' outside of loop

You attempted to use the continue statement outside of a loop. The continue statement can be used only within the body of a:

  • do-while loop,
  • while loop,
  • for loop,
  • for/in loop.

To correct this error

Make sure the continue statement appears within the body of a:

  • do-while loop,
  • while loop,
  • for loop,
  • for/in loop.
1023 Expected hexadecimal digit

You created an incorrect Unicode escape sequence. Unicode escape sequences begin with \u, followed by exactly four hexadecimal digits (no more and no less). Unicode hexadecimal digits can contain only the numbers 0-9, the upper case letters A-F, and the lower case letters a-f. The following example demonstrates a correctly formed Unicode escape sequence.

z = "\u1A5F";

To correct this error

Be sure your Unicode hexadecimal digits begin with \u, contains only the numbers 0-9, the upper case letters A-F, the lower case letters a-f; and are grouped into four digits.

Note   If you want to use the literal text \u in a string, then use two backslashes - (\\u) - one to escape the first backslash.

1024 Expected 'while'

You did not include the while condition in a do … while loop. A do statement must have a corresponding while test at the end of the code block.

To correct this error

Include the while test statement after the closing curly brace.

1025 Label redefined

You created a new label, but gave it the name of an existing label. Labels can be used to mark blocks of code, but within a specified scope, they must be unique.

To correct this error

Ensure that all labels you use in your programs are unique within their respective scopes.

1026 Label not found

You made a reference to a label that does not exist. Labels can be used to mark blocks of code, but within a specified scope, must be unique.

To correct this error

  • Check to make sure you did not misspell the label name.
  • Ensure all label references are made to labels that have been defined in the current scope (this includes forward definitions).
1027 'default' can only appear once in a 'switch' statement

You attempted to use the default statement more than once within a switch statement. The default case is always the last case statement in a switch statement (it is the fall-through case).

To correct this error

Remove any extra default case statements from your switch statement (use at most one default case statement in your switch statement).

1028 Expected identifier, string or number

You used incorrect literal syntax to declare an object literal. The properties of an object literal must be an identifier, a string, or a number. An object literal (also called an "object initializer") consists of a comma-separated list of property:value pairs, all enclosed within brackets. For example:

var point = {x:1.2, y:-3.4};

To correct this error

Ensure you use the proper literal syntax.

1029 Expected '@end'

You attempted to create a conditionally compiled block of code, but did not include the @end statement at the end. JScript statements can be conditionally compiled by enclosing them within an @if/@end block.

To correct this error

Add the corresponding @end statement.

1030 Conditional compilation is turned off

You attempted to use a conditional compilation variable without first turning conditional compilation on. Turning on conditional compilation tells the JScript compiler to interpret identifiers beginning with @ as conditional compilation variables. You do this by beginning your conditional code with the statement:

/*@cc_on @*/

To correct this error

Add the following statement to the beginning of your conditional code:

/*@cc_on @*/
1031 Expected constant

You attempted to use a (non-conditional compilation) variable in a conditional compilation test statement. Conditional compilation test statements must evaluate to a constant.

To correct this error

  • Replace the variable with a literal.
  • Replace the variable with a conditional compilation variable.
1032 Expected '@'

You attempted to create a variable to be used with conditional compilation statements using the @set statement, but did not place an at sign "@" before the variable name.

To correct this error

Add an at sign "@" immediately before the variable name. For example:

@set @myvar = 1
1033 Expected 'catch'

You used the exception handling try block, but did not write the associated catch statement. The exception handling mechanism requires that the code that can fail, along with the code that should not execute if an exception occurs, be wrapped inside a try block. Exceptions are thrown from within the try block using the throw statement, and caught outside the try block with one or more catch statements.

To correct this error

  • Add the associated catch block.
  • Try using a finally block instead of a catch block.
1035 Throw must be followed by an expression on the same source line

You used the throw keyword, but did not follow it with an expression on the same source line. A throw statement consists of two parts: the throw keyword, followed by the expression to be thrown. For example:

if (denominator == 0) {
 throw new DivideByZeroException();
}

You cannot split these two components up.

To correct this error

Make sure that the throw keyword and the expression to be thrown appears on the same line.