0

In jquery jQuery.fx.off will return bool. But when I am executing the following line I am getting undefined.

alert(jQuery.fx.off);

Please tell me why is it so.

wpercy
  • 9,636
  • 4
  • 33
  • 45

1 Answers1

2

In recent versions, at least, jQuery doesn't assign an initial value to jQuery.fx.off, leaving it undefined by default.

jQuery just tests whether it has a value and if that value is truthy:

jQuery.speed = function( speed, easing, fn ) {
    // ...

    opt.duration = jQuery.fx.off ? 0 : // ...
        //         ^^^^^^^^^^^^^

To get a boolean based on its truthiness, you can use the Boolean() function (without new) or double !!:

alert(jQuery.fx.off); // undefined

var fxOff = Boolean(jQuery.fx.off);
alert(fxOff);         // false
Community
  • 1
  • 1
Jonathan Lonowski
  • 121,453
  • 34
  • 200
  • 199