1

When I run JSlint on this piece of code I get this error

Error: Problem at line 25 character 26: 'selectedDate' is already defined. var selectedDate = new Date(selectedDate);

Implied global: $ 1,4,13,14,26,27,28,31,33,34,42, updateSelects 13,19,21

http://jsfiddle.net/bzPYg/

I think it is referring to this code

'dateSelected', function(e, selectedDate, $td, state) {
    updateSelects(selectedDate);

How can I fix this?

Thanks

grappler
  • 527
  • 5
  • 17

1 Answers1

1

The error sort of explains itself.

Problem at line 25 character 26: 'selectedDate' is already defined. var selectedDate = new Date(selectedDate);

You are declaring the variable selectedDate again, and you are filling it with a new Date object taking in the value of the original variable selectedDate. You should rename the variable to something else.

var date = new Date(selectedDate);

And just to note the error is occuring here:

var updateSelects = function(selectedDate) {
   var selectedDate = new Date(selectedDate);
   ...
});
Josh Mein
  • 28,107
  • 15
  • 76
  • 87
  • This is called *variable shadowing* and [this answer](http://stackoverflow.com/a/11963373/451969) gives a decent explanation. – Jared Farrish Aug 18 '12 at 19:27
  • Thanks I changed the slectedDate to selectDate and JSlint doesnt give me any errors any more. So thanks. – grappler Aug 19 '12 at 20:57