Answer the question
In order to leave comments, you need to log in
Why do you need undefined at the beginning of jquery code?
I started learning JavaScript using the jQuery library as an example. A question arose immediately.
The whole library is in an anonymous function, like this
(function( window, undefined ) { /*тут много тысяч строк кода библиотеки*/ })( window );<br>
Answer the question
In order to leave comments, you need to log in
undefined is just like any other variable and can be redefined. And this technique allows you to correctly initialize it in the scope of this function
This declares an undefined variable, which has nothing to do with "typeof variable == 'undefined'), other than similar sound and name.
This variable will be undefined. And it can be used to check that another variable is not defined, only with a triple equal sign:
var t;
This:
if (t === undefined) {
}
will have the same effect as
if (typeof t == 'undefined') {
}
But shorter.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question