Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there a datatype with thee different values like a boolean

Is there a datatype in javaScript or PHP etc. that can contain just a view different custom values. Like a boolean but with three types. Like something like this:
the value must be one of the following things "above", "under" or "in the middle".

like image 312
Nils Avatar asked Dec 17 '25 11:12

Nils


1 Answers

Hey in JavaScript there is no such thing, but you can use number and create some kind of enum like this

const ENUM = {
  ABOVE: 1,
  MIDDLE: 0,
  UNDER: -1
}

and then use it like this:


function acceptValue(en) {
  if (en === ENUM.ABOVE) {
    /* do something */
  }
}
like image 133
Evgeny Klimenchenko Avatar answered Dec 20 '25 01:12

Evgeny Klimenchenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!