JSHint error - Expected an assignment or function call and instead saw an expression

StackOverflow https://stackoverflow.com/questions/9083557

  •  06-12-2019
  •  | 
  •  

Question

Why does the following code trigger "Expected an assignment or function call and instead saw an expression." in JSHint? I thought this was the correct way to protect a block from executing if a particular variable or variables are not defined...

!function($) {
    "use strict";

    // jQuery-based code here
    $('.test').show();
}(window.jQuery);
Was it helpful?

Solution

Remove the ! in front of function and all should be well. Which prompts me to ask why it is there in the first place since the function returns no value.

Any expression, as opposed to assignment, is flagged by JSHint with the message you quote.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top