ifIs()

If the first and second arguments are the same the third argument is passed back, otherwise the fourth argument (or if not given the first argument) is passed back.

This function is valid in v2.13.0 to v2.24.3. This function has been downloaded 61 times.

Parameters

{*} subject
Value to test.
{*} control
Value that is being tested against.
{*} trueValue
Value to be returned if control and subject are the same.
{*=} opt_falseValue Optional, Default:subject
Value to be returned if control and subject are different.

Returns

{*}
trueValue will be returned if control is subject. Otherwise, if opt_falseValue is given it will be returned, but if not given subject will be returned.

Required Functions

This function directly requires the following functions which are included automatically:

  • ifExcludes()
    If the second argument is not in the first argument (array) the third argument is passed back, otherwise the fourth argument (or if not given the first argument) is passed back.
  • ifFail()
    Tests subject against control and if it results in a false-ish value falsyValue will be passed back. Otherwise, if opt_truthyValue is given it will be passed back, but if not subject will be passed back.
  • ifFails()
    Tests subject against control and if it results in a false-ish value falsyValue will be passed back. Otherwise, if opt_truthyValue is given it will be passed back, but if not control will be passed back.
  • ifIn()
    If the first argument is in the second argument (array) the third argument is passed back, otherwise the fourth argument (or if not given the first argument) is passed back.
  • ifIncludes()
    If the second argument is in the first argument (array) the third argument is passed back, otherwise the fourth argument (or if not given the first argument) is passed back.
  • ifNot()
    If the first and second arguments are different the third argument is passed back, otherwise the fourth argument (or if not given the first argument) is passed back.
  • ifOut()
    If the first argument is not in the second argument (array) the third argument is passed back, otherwise the fourth argument (or if not given the first argument) is passed back.
  • ifPass()
    Tests subject against control and if it results in a true-ish value truthyValue will be passed back. Otherwise, if opt_falsyValue is given it will be passed back, but if not subject will be passed back.
  • ifPasses()
    Tests subject against control and if it results in a true-ish value truthyValue will be passed back. Otherwise, if opt_falsyValue is given it will be passed back, but if not control will be passed back.
  • indexOf()
    Gets the index of a specified target value in a string, array or an object. Unlike Array.prototype.indexOf(), this function works for finding NaN and differentiates between -0 and 0.

Requiring Functions

This function is directly required by the following functions:

  • ifExcludes()
    If the second argument is not in the first argument (array) the third argument is passed back, otherwise the fourth argument (or if not given the first argument) is passed back.
  • ifFail()
    Tests subject against control and if it results in a false-ish value falsyValue will be passed back. Otherwise, if opt_truthyValue is given it will be passed back, but if not subject will be passed back.
  • ifFails()
    Tests subject against control and if it results in a false-ish value falsyValue will be passed back. Otherwise, if opt_truthyValue is given it will be passed back, but if not control will be passed back.
  • ifIn()
    If the first argument is in the second argument (array) the third argument is passed back, otherwise the fourth argument (or if not given the first argument) is passed back.
  • ifIncludes()
    If the second argument is in the first argument (array) the third argument is passed back, otherwise the fourth argument (or if not given the first argument) is passed back.
  • ifNot()
    If the first and second arguments are different the third argument is passed back, otherwise the fourth argument (or if not given the first argument) is passed back.
  • ifOut()
    If the first argument is not in the second argument (array) the third argument is passed back, otherwise the fourth argument (or if not given the first argument) is passed back.
  • ifPass()
    Tests subject against control and if it results in a true-ish value truthyValue will be passed back. Otherwise, if opt_falsyValue is given it will be passed back, but if not subject will be passed back.
  • ifPasses()
    Tests subject against control and if it results in a true-ish value truthyValue will be passed back. Otherwise, if opt_falsyValue is given it will be passed back, but if not control will be passed back.