Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Missing semicolon' warning in Eclipse for JavaScript code

Eclipse gives me the warning 'Missing semicolon' for line 4 of the following code:

const C = 'b';
function foo() {
    alert('x');
}

It does not for the following code:

//const C = 'b';
function foo() {
    alert('x');
}

For the following it gives me two warnings:

const C = 'b';
function foo() {
    alert('x');
};

Multiple markers at this line

  • Unnecessary semicolon
  • Missing semicolon

Is there a way to make Eclipse ignore my lines with 'const'? Or is there another way to solve my problem?

I am using:

Eclipse IDE for JavaScript Web Developers.
Version: Indigo Service Release 1
Build id: 20110916-0149

like image 666
user1027167 Avatar asked Mar 01 '12 08:03

user1027167


People also ask

What happens if semicolon is missing in JavaScript?

The JavaScript exception "missing ; before statement" occurs when there is a semicolon ( ; ) missing somewhere and can't be added by automatic semicolon insertion (ASI). You need to provide a semicolon, so that JavaScript can parse the source code correctly.

Is semicolon required for JavaScript?

Semicolons are not required for JavaScript programming, nevertheless I advice you to use it. It makes your code more readable and is actually a good practice, and almost all cool programming languages uses it. Take a stand and use it, it's up to you now!

How do you use semicolons in JavaScript?

The rules of JavaScript Automatic Semicolon Insertionwhen the next line starts with code that breaks the current one (code can spawn on multiple lines) when the next line starts with a } , closing the current block. when the end of the source code file is reached. when there is a return statement on its own line.

How do you fix a semicolon error?

Changing the semicolon to a comma would correct the sentence's error.


2 Answers

There is only a proposed const in JavaScript. Use

var C = 'b';

Actually, there is a const apparently, but it is not supported by all browsers and would not be good to use for that reason.

The reason Eclipse is giving you the warning is that it does not recognize const which is a known bug in Eclipse.

You can read how to ignore the errors in Use of JavaScript const gives "missing semicolon" in associative....

like image 114
Asken Avatar answered Oct 13 '22 00:10

Asken


You may disable some warnings in the preference menu:

Disabling warnings in preference -> Javascript -> Validator -> Error and warnings

like image 30
borjab Avatar answered Oct 12 '22 22:10

borjab