Why does JSHint throw a warning if I am using const?

后端 未结 17 2966
眼角桃花
眼角桃花 2020-12-12 08:18

This is the error I get when using const:



        
相关标签:
17条回答
  • 2020-12-12 09:07

    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

    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}

    0 讨论(0)
  • 2020-12-12 09:09

    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

    0 讨论(0)
  • 2020-12-12 09:14

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

    0 讨论(0)
  • 2020-12-12 09:14

    If using Sublime Text 3:

    • Go to Preferences -> Settings
    • Under Preferences.sublime-settings—User add "esversion": 6
    0 讨论(0)
  • 2020-12-12 09:15

    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
    }
    
    0 讨论(0)
提交回复
热议问题