DiviArea.Utils.toBool()

  1. Home
  2. Knowledge Base
  3. Codex
  4. JS API
  5. JS Functions
  6. DiviArea.Utils.toBool()
DiviArea.Utils.toBool(value, undefinedValue)

Utility that tests, if a value equals to boolean true.

See below for a list of values that are considered true or false.

Params

value
(mixed, required) The value which should be converted to a boolean value.
undefinedValue
(bool, optional) A boolean value to assign if the test value is undefined.
Default: true

Returns

Either boolean true or false.

Notes

The following values are considered true:

  • true
  • 1
  • string starting with y (like yes)
  • string starting with t (like true)
  • the string on

The following values are considered false:

  • false
  • 0
  • string starting with n (like no)
  • string starting with f (like false)
  • the string off

If the value is undefined the parameter undefinedValue is returned.

Any other value is type-casted to boolean by JavaScript.

Was this article helpful?

Related Articles