Skip to content Skip to sidebar Skip to footer

What Does "undefined" Parameter Signify In A Function Definition

I was reverse engineering a jQuery plugin and found a peculiar function definition. function myFunction(value, undefined){ ... } Of course, this works but similar declarations l

Solution 1:

Oddly, undefined is not a reserved keyword and its global value can be overridden (or could be in the past, in some runtime environments). Thus that trick provides a way to wrap code expecting undefined to really be undefined: when that function is called, if only one parameter is passed the second argument, called "undefined", will have the authentic undefined value inside the function.

Why would undefined be overwritten? Who knows. People who write code for pages that also have to host 3rd-party code (generally adverts and things like that) become paranoid and defensive after a while.

Post a Comment for "What Does "undefined" Parameter Signify In A Function Definition"