Hướng dẫn dùng esversion JavaScript

This is the error I get when using const:


My code looks like this:

const Suites = {
    Spade: 1,
    Heart: 2,
    Diamond: 3,
    Club: 4
};

The code works fine only JSHint is warning me every time.

Hướng dẫn dùng esversion JavaScript

Zanon

26.8k20 gold badges109 silver badges122 bronze badges

asked Dec 12, 2014 at 10:39

3

When relying upon ECMAScript 6 features such as const, you should set this option so JSHint doesn't raise unnecessary warnings.

/*jshint esnext: true */ (Edit 2015.12.29: updated syntax to reflect @Olga's comments)

/*jshint esversion: 6 */

const Suites = {
    Spade: 1,
    Heart: 2,
    Diamond: 3,
    Club: 4
};

This option, as the name suggests, tells JSHint that your code uses ECMAScript 6 specific syntax. http://jshint.com/docs/options/#esversion

Edit 2017.06.11: added another option based on this answer.

While inline configuration works well for an individual file, you can also enable this setting for the entire project by creating a .jshintrc file in your project's root and adding it there.

{
  "esversion": 6
}

answered Dec 12, 2014 at 11:05

Hướng dẫn dùng esversion JavaScript

James HibbardJames Hibbard

15.5k11 gold badges59 silver badges70 bronze badges

7

You can add a file named .jshintrc in your app's root with the following content to apply this setting for the whole solution:

{
    "esversion": 6
}

James' answer suggests that you can add a comment /*jshint esversion: 6 */ for each file, but it is more work than necessary if you need to control many files.

Hướng dẫn dùng esversion JavaScript

answered May 27, 2016 at 0:12

Hướng dẫn dùng esversion JavaScript

3

I got this same warning when using an export statement. I'm using VS Code and used a similar approach to Wenlong Jiang's solution.

  1. User Settings

  2. JSHint config

  3. "jshint.config": {} (Edit)

  4. Use double quotes when specifying "esversion"

    Or copy this snippet into User Settings:

    "jshint.options": {
      "esversion": 6,
    }
    

Creating a .jshintrc file isn't necessary if you want to configure the global jshint settings for your editor

answered Oct 4, 2017 at 14:59

3

If you're using VSCode:

1.

  • Go to preferences -> settings (cmd + ,)
  • Type jshint.options into the search bar
  • Hover over it and click on the pencil icon
  • Its now appended on the right side.
  • Add "esversion": 6 to the options object.

2.

Or simply add this to your user settings:

"jshint.options": {
    "esversion": 6
}

[UPDATE] new vscode settings

  • Go to preferences -> settings (cmd + ,)
  • type jshint into search

Hướng dẫn dùng esversion JavaScript

  • continue with step 2.

answered Mar 2, 2018 at 16:21

Hướng dẫn dùng esversion JavaScript

PhilipPhilip

3,3461 gold badge23 silver badges35 bronze badges

0

I spent ages trying to fix this. Every solution talks about 'setting options'. I don't know what that means. Finally, I figured it out. You can just include a commented out line at the top of the file /*jshint esversion: 6 */.

Hướng dẫn dùng esversion JavaScript

Hướng dẫn dùng esversion JavaScript

Zanon

26.8k20 gold badges109 silver badges122 bronze badges

answered Feb 12, 2016 at 14:27

Hướng dẫn dùng esversion JavaScript

Josh PittmanJosh Pittman

6,5846 gold badges34 silver badges62 bronze badges

4

You can specify esversion:6 inside jshint options object. Please see the image. I am using grunt-contrib-jshint plugin.

Hướng dẫn dùng esversion JavaScript

Hướng dẫn dùng esversion JavaScript

Ramzi Khahil

4,7444 gold badges34 silver badges68 bronze badges

answered Feb 7, 2017 at 19:06

Hướng dẫn dùng esversion JavaScript

2

Create .jshintrc file in the root dir and add there the latest js version: "esversion": 9 and asi version: "asi": true (it will help you to avoid using semicolons)

{
    "esversion": 9,
    "asi": true
}

answered May 24, 2020 at 3:12

JohnPixJohnPix

1,32114 silver badges36 bronze badges

When you start using ECMAScript 6 this error thrown by your IDE.

There are two options available:

if you have only one file and want to use the es6 then simply add below line at the top of the file.

/*jshint esversion: 6 */

Or if you have number of js file or you are using any framework(like nodejs express)you can create a new file named .jshintrc in your root directory and add code below in the file:

{
    "esversion": 6
}

If you want to use the es6 version onward for each project you can configure your IDE.

answered Jul 7, 2018 at 8:16

Hướng dẫn dùng esversion JavaScript

Prashant BarvePrashant Barve

3,9852 gold badges32 silver badges42 bronze badges

1

In your package.json you can tell Jshint to use es6 like this

"jshintConfig":{
    "esversion": 6 
}

answered Oct 16, 2019 at 6:45

Hướng dẫn dùng esversion JavaScript

SinghakSinghak

8,0442 gold badges29 silver badges34 bronze badges

1

For SublimeText 3 on Mac:

  1. Create a .jshintrc file in your root directory (or wherever you prefer) and specify the esversion:
    # .jshintrc
    {
      "esversion": 6
    }
  1. Reference the pwd of the file you just created in SublimeLinter user settings (Sublime Text > Preference > Package Settings > SublimeLinter > Settings)
    // SublimeLinter Settings - User
    {
      "linters": {
        "jshint": {
          "args": ["--config", "/Users/[your_username]/.jshintrc"]
        }
      }
    }
  1. Quit and relaunch SublimeText

QuickSilver

3,7862 gold badges12 silver badges28 bronze badges

answered Apr 25, 2020 at 18:03

Creating a .jshintrc file is not necessary.

If you are using ECMAScript 6 then all you need to do is tell JSHint that:

  1. Go to File > Settings
  2. Navigate to Languages & Frameworks > JavaScript > Code Quality Tools > JSHint.
  3. Scroll down to find Warn about incompatibilities with the specified ECMAScript version.
  4. Click on Set.
  5. Enter 6 and then press [Set].
  6. Click [OK]

answered Feb 25, 2021 at 21:35

xtemporextempore

5,0694 gold badges32 silver badges42 bronze badges

If you are using Webstorm and if you don't have your own config file, then just enable EcmaScript.next in Relaxing options in in

Settings | Languages & Frameworks | JavaScript | Code Quality Tools | JSHint

See this question How-do-I-resolve-these-JSHint-ES6-errors

answered Sep 29, 2018 at 13:38

Hướng dẫn dùng esversion JavaScript

Sudhanshu GaurSudhanshu Gaur

7,1599 gold badges42 silver badges88 bronze badges

If you are using Grunt configuration, You need to do the following steps

Warning message in Jshint:

Hướng dẫn dùng esversion JavaScript

Solution:

  1. Set the jshint options and map the .jshintrc.js file

Hướng dẫn dùng esversion JavaScript

  1. Create the .jshintrc.js file in that file add the following code
{  
  "esversion": 6  
} 

After configured this, Run again It will skip the warning,

Hướng dẫn dùng esversion JavaScript

answered Oct 24, 2018 at 12:40

Hướng dẫn dùng esversion JavaScript

SridharSridhar

3515 silver badges10 bronze badges

Create a file called, say jshint_opts with this content: { "esversion": 6 }

Then invoke jshint with something like this command line:

jshint --config jshint_opts lib/*.js

answered Dec 7, 2017 at 21:40

May 2020 Here's a simple solution i found and it will resolve for all of my projects ,on windows if your project is somewhere inside c: directory , create new file .jshintrc and save it in C directory open this .jshintrc file and write { "esversion": 6} and that's it. the warnings should go away , same will work in d directory

Hướng dẫn dùng esversion JavaScript

Hướng dẫn dùng esversion JavaScript
yes you can also enable this setting for the specific project only by same creating a .jshintrc file in your project's root and adding { "esversion": 6}

answered May 3, 2020 at 11:07

Hướng dẫn dùng esversion JavaScript

Kunal RajputKunal Rajput

5061 gold badge6 silver badges16 bronze badges

To fix this in Dreamweaver CC 2018, I went to preferences, edit rule set - select JS, edit/apply changes, find "esnext" and changed the false setting to true. It worked for me after hours of research. Hope it helps others.

answered Jun 17, 2020 at 1:47

Hướng dẫn dùng esversion JavaScript

I had the same issue, and I found that by adding:

/* jshint esversion: 8 */

(or whatever jshint esversion you need, like 6)

To the top of my .js file satisfies the cause for the warnings.

answered Jan 27 at 1:56

If using Sublime Text 3:

  • Go to Preferences -> Settings
  • Under Preferences.sublime-settings—User add "esversion": 6

answered Jul 3, 2018 at 20:58

London804London804

9531 gold badge18 silver badges40 bronze badges

0

In a new version of Dreamweaver to solve this error

  • Go to Edit->Preference->Linting
  • And the go-to js Edit rule set and past

    "jshintConfig":{ "esversion": 6 }

answered Apr 12, 2020 at 9:33

Hướng dẫn dùng esversion JavaScript

Not the answer you're looking for? Browse other questions tagged javascript node.js constants jslint jshint or ask your own question.