"alert" is not detected when starting www.jshint.com

I fixed this by simply adding var alert; However, is this what I should do to get away from the error message? Here is the fix. Here is the failure of www.jshint.com .

I am trying to learn from the mistake he throws. Itโ€™s not necessary to make them leave.

 (function () { "use strict"; var alert; // added this in to fix function initialize_page() { alert ("hi"); } addEventListener('load', initialize_page); })(); 
+49
javascript
Nov 17 '11 at 19:52
source share
8 answers

This documentation talks about the browser option:

This parameter defines global variables opened by modern browsers: from a good document and navigator to HTML5 FileReader and other new developments in the browser world. Note. This parameter does not provide variables such as a warning or console. For more information, see Development Option.

and the following about the devel option:

This parameter defines global variables that are commonly used to record bad debugging: console, warning, etc. It is usually recommended not to send them to production, because, for example, console.log is broken into legacy versions of Internet Explorer.

You have a browser enabled and disabled. You can manage them using the checkboxes in the "Assume" box on the jshint original page. I also recommend listening to the warning in the documentation; -)

+61
Nov 17 '11 at 20:01
source share

Instead

 alert('message') 

you should use

 window.alert('message'); 

Because this method is defined in the window object .

This of course assumes that you have the browser option set to true in your .jshintrc , so that jshint will know that the window object is open.

 "browser" : true, // Standard browser globals eg window, document. 

* The same thing happens with confirm() .

+58
May 9 '14 at 8:57
source share

Set "devel: true" to "Options". This allows you to use features such as alerts, console, etc.

See the documentation here: http://jshint.com/docs/options/

+24
Nov 17 2018-11-11T00:
source share
 function prod(arr) { let largest = 0; let secondLargest = 0; const len = arr.length; for (let i = 0; i < len; i++) { if (arr[i] > largest) { secondLargest = largest; largest = arr[i]; } else if (arr[i] < largest && arr[i] > second_largest) { secondLargest = arr[i] } } return largest * secondLargest; } console.log(prod([2, 4, 7, 8])); 
0
Jan 11 '18 at 6:45
source share

use the .jshintrc file

in js alert (data.status); or window.alert (data.status);

 "window": true, "alert": true 

or better

 "devel": true, { "esversion": 6, "browser": true, "undef": true, "varstmt": true, "forin": true, "unused": true, "funcscope": true, "lastsemic": true, "moz": true, "jquery": true, "module": true, "devel": true, "globals": { "window": true, "document": true, "console": true, "alert": true } 

}

0
Dec 10 '18 at 18:08
source share

Instead:

 alert('message') 

I use:

 var alert = window['alert']; 
-2
Jul 07 '17 at 14:03
source share

try passing the window object to:

 (function (global) { "use strict"; var alert; // added this in to fix function initialize_page() { global.alert ("hi"); } addEventListener('load', initialize_page); })(window); 
-5
Nov 17 '11 at 19:59
source share

declare the warning as a variable, and it will work without any settings:

eg:

 var alert; alert('hello world'); 
-7
Mar 19 '15 at 20:19
source share



All Articles