Truthy values

In DinoCode, values can have an alternative representation as true or false.

Boolean data types

To review more about boolean data types (true/false), consult the Data types section.

Truthy values#

The following values can be represented as true:

Data typeExamples
IntegerAny number different from 0
FloatAny number different from 0.0
StringAny text with at least one character (not empty)
ArrayAny array with at least one element (not empty)
ObjectAny object with at least one property (not empty)
Falsy values

Values that are represented as false are: none, 0, 0.0, "" (empty string), [] (empty array) and {} (empty object).

Conversion to boolean#

You can see the boolean representation of any value using bool().

# Integer
print "1 is " bool(1)        # true
print "0 is " bool(0)        # false

# Float
print "0.0 is " bool(0.0)    # false
print "3.14 is " bool(3.14)  # true

# Infinities are truthy
print "infi is " bool(infi)  # true
print "-infi is " bool(-infi)  # true

# String
print "'' is " bool('')      # false
print "'a' is " bool('a')    # true

# None
print "none is " bool(none)  # false

# Array
print "[] is " bool([])      # false
print "[1] is " bool([1])    # true

# Object
print "{} is " bool({})      # false
print "{a: 1} is " bool({a: 1})  # true
NaN

NaN (Not a Number) values cause an error when attempting to represent them as booleans. Review the Data types section to understand more about what NaN is.