So… I’ve recently started running my code through JSHint, and its moaning about the following:
function myfunc(config){
var config = Ext.apply({},config,{});
//Ext.apply is used as a deep object clone, to check for defaults ,
//typeof config !==null, etc
}
‘var config is already defined’
I kinda figured it just works, and so far have not really had any problems with it.
What kinda gotcha’s are there for re-declaring a variable like this?
(and if you know how to, how do I disable the warning in JSHint?)
var configintroduces a new local-scoped variable that shadows any same-named variable from an outer scope. In your case, you’re redeclaring the variable within the same scope it is already defined in, so it actually works as you expect, but you do not need thevardeclaration, becauseconfigis already locally scoped.