Reputation: 1901
I have bundled these together because I think they are related. The most simplest of simple bits of code:
'use strict';
const x = document.querySelector('#score strong');
is resulting in the following
"use the function form of use strict (W097)"
"document is not defined (W117)"
which may be errors or warnings; the W suggests a warning but I don't know how to determine this.
So, another question: are these warnings, or errors, and how can I tell this for myself? Where is this referenced?
I am using Atom 1.31, with I think JSHint (whatever that is - I am new to all this). I am using ES6 - .jshintrc:
{
"esversion": 6
}
How should I be specifying use strict globally? Putting it in a function so that it's used globally means, er, putting the whole contents of my script inside a function. No? Yes?
And how do I circumvent this document is not defined thing? I have tried
const document=this.document;
const document=global.document;
const document=window.document;
All result in warnings/errors (whatever).
So, to be clear, my questions are:
are these warnings, or errors, and how can I tell this for myself?
how do I and indeed do I need to, circumvent the use strict thing?
how do I and indeed do I need to, circumvent the document is not defined thing?
Upvotes: 1
Views: 2825
Reputation: 224905
You’ll need to set the strict
option to prefer a global 'use strict'
, and the browser
option to tell JSHint that your script targets browsers.
.jshintrc
{
"esversion": 6,
"browser": true,
"strict": "global"
}
And yes, “W” at the beginning of a code means “warning”.
Upvotes: 8