In following code of javascript
second parameter kept undefined
, why is so?
(function(a,b){
...
})(window)
What is the technique behind this? Any reference to know about this technique?
In following code of javascript
second parameter kept undefined
, why is so?
(function(a,b){
...
})(window)
What is the technique behind this? Any reference to know about this technique?
You've asked this question about an hour ago. What did you expect? you're giving first parameter, after that javascript tries to find the others. if there are no more parameters given to function, all the others (b in your case) will be set to undefined. Javascript is not like C++ or java. There are no compile time errors because javascript is not compiling. So it tries to resolve problems itself. In this case if you pass less count of parameters it sets the others to undefined and works.
Here you require 2 parameters in the anonymous function, but you are only providing single parameter (window
). Thus the second parameter is always undefined.