HyperMath

Querying Type

Querying Type

Previous topic Next topic No expanding text in this topic  

Querying Type

Previous topic Next topic JavaScript is required for expanding text JavaScript is required for the print function  

Use the HyperMath function type()to get a description for a particular object type.

> x = "123"  // a string

> print(x, type(x)) // show the value of x and its type

123     string

 

> x = x + 7  // add a number to the string which forces coercion

> print(x, type(x)) // again show the value and type

1237     string

 

> x = 7

> print(x, type(x))

7        number

The type()function can be used to determine if the input passed to the script is of the correct type or not.

> z = type(x)

if (z == "number"){

 print("The input value is a number & the value is:", x)

} else {

 print("The input value is not a number. Please input numbers to the script.")

}

 

> The input value is a number & the value is:    7