DocsPlaygroundBlogCommunityPackages
  • Playground
  • Blog
  • Community
  • Packages
  • X
  • Bluesky
  • GitHub
  • Forum
Language ManualAPISyntax LookupReact
Overview
Stdlib
submodules
  • Array
  • ArrayBuffer
  • AsyncIterator
  • BigInt
  • BigInt64Array
    • Constants
    BigUint64Array
    • Constants
  • Bool
    • t
      t
    • v
      toString
    • v
      fromString
    • v
      fromStringOrThrow
    • v
      fromStringExn
      D
    • v
      compare
    • v
      equal
  • Console
  • DataView
  • Date
    • UTC
  • Dict
  • Error
    • URIError
    • TypeError
    • SyntaxError
    • ReferenceError
    • RangeError
    • EvalError
  • Exn
  • Float
    • Constants
    Float32Array
    • Constants
    Float64Array
    • Constants
    Int
    • Ref
    • Bitwise
    • Constants
    Int16Array
    • Constants
    Int32Array
    • Constants
    Int8Array
    • Constants
  • IntervalId
  • Intl
    • Segments
    • Segmenter
    • RelativeTimeFormat
    • PluralRules
    • NumberFormat
      • Grouping
    • Locale
    • ListFormat
    • DateTimeFormat
    • Collator
    • Common
  • Iterator
  • JSON
    • Decode
    • Encode
    • Classify
    JsError
    • URIError
    • TypeError
    • SyntaxError
    • ReferenceError
    • RangeError
    • EvalError
  • JsExn
  • Lazy
  • List
  • Map
  • Math
    • Int
    • Constants
  • Null
  • Nullable
  • Object
  • Option
  • Ordering
  • Pair
  • Promise
  • RegExp
    • Result
  • Result
  • Set
  • String
  • Symbol
  • TimeoutId
  • Type
    • Classify
  • TypedArray
  • Uint16Array
    • Constants
    Uint32Array
    • Constants
    Uint8Array
    • Constants
    Uint8ClampedArray
    • Constants
  • WeakMap
  • WeakSet
  • Docs / API / Stdlib / Bool

    Bool

    Functions for interacting with JavaScript booleans. See: Boolean

    t

    RESCRIPT
    type t = bool

    Type representing a boolean.

    toString

    RESCRIPT
    let toString: bool => string

    Converts a boolean to a string.

    Examples

    RESCRIPT
    Bool.toString(true) == "true" Bool.toString(false) == "false"

    fromString

    RESCRIPT
    let fromString: string => option<bool>

    Converts a string to a boolean.

    Examples

    RESCRIPT
    Bool.fromString("true") == Some(true) Bool.fromString("false") == Some(false) Bool.fromString("notAValidBoolean") == None

    fromStringOrThrow

    RESCRIPT
    let fromStringOrThrow: string => bool

    Converts a string to a boolean. Throws an Invalid_argument exception if the string is not a valid boolean.

    Examples

    RESCRIPT
    Bool.fromStringOrThrow("true") == true Bool.fromStringOrThrow("false") == false switch Bool.fromStringOrThrow("notAValidBoolean") { | exception Invalid_argument(_) => assert(true) | _ => assert(false) }

    fromStringExn

    Deprecated

    RESCRIPT
    let fromStringExn: string => bool

    Converts a string to a boolean. Beware, this function will throw an Invalid_argument exception if the string is not a valid boolean.

    Examples

    RESCRIPT
    Bool.fromStringExn("true") == true Bool.fromStringExn("false") == false switch Bool.fromStringExn("notAValidBoolean") { | exception Invalid_argument(_) => assert(true) | _ => assert(false) }

    compare

    RESCRIPT
    let compare: (bool, bool) => Ordering.t

    Compares two booleans, returns an Ordering.t value.

    Examples

    RESCRIPT
    Bool.compare(true, true) == Ordering.equal Bool.compare(false, false) == Ordering.equal Bool.compare(true, false) == Ordering.greater Bool.compare(false, true) == Ordering.less

    equal

    RESCRIPT
    let equal: (bool, bool) => bool

    Checks if two booleans are equal and have the same value.

    Examples

    RESCRIPT
    Bool.equal(true, true) == true Bool.equal(false, false) == true Bool.equal(true, false) == false Bool.equal(false, true) == false
    Types and values
    • t
      t
    • v
      toString
    • v
      fromString
    • v
      fromStringOrThrow
    • v
      fromStringExn
      D
    • v
      compare
    • v
      equal

    © 2025 The ReScript Project

    About
    • Community
    • ReScript Association
    Find us on