Reputation: 10256
What are JavaScript/jQuery variable names i should avoid creating that could conflict with already existing Global variables. Yesterday i discovered that i cannot use the variable default
. It must be a global variable.
Upvotes: 2
Views: 1391
Reputation: 57
when building jQuery plugins, be aware that $.fn.init = function() could lead to problems and you should rather use another name for your function. http://www.sarahleeashraf.com/explaining-jquery-part-2-init-function
Upvotes: 1
Reputation: 46517
These are JavaScript's reserved words:
You should avoid naming you variables the same as that list.
I hope this helps.
Hristo
Upvotes: 2
Reputation: 1482
Take a look at:
http://jqfundamentals.com/book/index.html
There's a special content of reserved words.
Upvotes: 1
Reputation: 237965
default
is not a global variable: it is a reserved word (it's used in switch
statements).
You can find a list of reserved keywords on the MDC website.
Note also that there are various other names that you should be careful with. For instance, a variable named location
could conflict with the window.location
object unless you're careful. For this reason (among others), you should avoid global variables.
Other such variables are:
window.top
window.parent
window.document
window.self
Upvotes: 4
Reputation: 21378
default is a JavaScript keyword:
switch(foo)
{
case a:
break;
default:
break;
}
As for jQuery reserved words, check out this link (scroll down to the "Reserved Words" section)
Upvotes: 2
Reputation: 73011
default
is not a global variable, it's a reserved word in JavaScript.
If you are going to use global variables, you should namespace them.
Upvotes: 1
Reputation: 44215
default is one of the JavaScript reserved words (which is also the list of variables to avoid using). jQuery wise it is $ although you can use jQuery in no conflict mode.
Upvotes: 3