This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 226477 - const not recognized in JavaScript
Summary: const not recognized in JavaScript
Status: RESOLVED DUPLICATE of bug 238942
Alias: None
Product: javascript
Classification: Unclassified
Component: Editor (show other bugs)
Version: 7.3.1
Hardware: PC Windows 7 x64
: P3 normal with 8 votes (vote)
Assignee: Petr Pisl
: 239881 (view as bug list)
Depends on:
Reported: 2013-02-21 19:43 UTC by geverl
Modified: 2015-06-22 13:49 UTC (History)
6 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Note You need to log in before you can comment on or make changes to this bug.
Description geverl 2013-02-21 19:43:39 UTC
NB 7.2 handled this fine, but NB 7.3 claims "Expected an operand but found const" for a simple line like this one: const pi = 3.14;
Comment 1 Petr Pisl 2013-02-21 20:49:46 UTC
This comes from parser. In NB 7.2 was used Rhino parser, in NB 7.3 is used Nashorn parser. 

The current implementation of const is a Mozilla-specific extension and is not part of ECMAScript 5 and this is the reason, why it worked in NB 7.2. The Rhino parser is Mozilla's parser.

The proper fix should be on parser site, in NetBeans I can filter the message, but is not very nice approach.
Comment 2 meanyack 2013-02-26 12:07:16 UTC
I made some tests, Chrome and Mozilla handles const keyword. However, even internet explorer 10 fails. Therefore, it's safe not to use const keyword.
Comment 3 geverl 2013-02-26 16:14:53 UTC
I know that IE does not recognize it, but that's a Microsoft issue.
const is part of the JavaScript language and as such should be recognized correctly.
Comment 4 Petr Pisl 2013-02-26 18:49:41 UTC
to geverl: const is not a part of JavaScript specification ECMAScript-262 Edition 5.1 language (fallowed with Nashorn). As I wrote - const is a Mozilla-specific extension and is not a part of ECMAScript 5. So from this point of view it depends how you specify JavaScript language. 

So I can block the message in the editor, but the file will not be fully parsed by the parser.
Comment 5 geverl 2013-02-26 20:41:16 UTC
OK, thanks for your explanations.
I can live without const, so I'm just going to mark this as resolved.
Comment 6 Lope 2013-08-26 19:07:08 UTC
I make use of many libraries that use const and as a result Netbeans is not working properly.

Lets at least add an option to ignore this parser error?
Comment 7 jnurthen 2013-09-27 20:29:12 UTC
I want to echo the comment to let us ignore the error. 
I sometimes work with libraries which use const and am developing code which is mozilla-only (for an Add-on). I don't care that IE doesn't support it, I just need to suppress the errors without having to revert back to 7.2
Comment 8 Vladimir Riha 2014-01-02 07:03:55 UTC
*** Bug 239881 has been marked as a duplicate of this bug. ***
Comment 9 peterkehl 2014-05-06 23:01:07 UTC
'const' is not in ECMAScript 5, but it will be in ECMAScript 6:

As others, I also depend on 'const' because I develop Mozilla add-ons. Please, implement this.
Comment 10 Christian Lenz 2014-07-01 11:02:15 UTC
Have to use it too, and the IDE shows me the same error: "Expected an operand but found const". Voted.
Comment 11 peterkehl 2014-10-16 22:42:08 UTC
Also, Mozilla now documents 'const' keyword at
Comment 12 Roman Svitanic 2015-06-22 13:49:21 UTC

*** This bug has been marked as a duplicate of bug 238942 ***