type()
noahpgordon38 total contributions
Published Oct 18, 2023
Contribute to Docs
The type()
method takes an argument and returns a value corresponding to the type of that argument in the following manner:
- If the value of the argument is an integer,
"integer"
will be returned. - If the value of the argument is a float,
"float"
will be returned. - For all other values,
nil
will be returned.
Syntax
The syntax of type()
is as follows:
math.type(arg)
Where arg
is the argument to be checked for its type.
Examples
The following examples illustrate the behavior of type()
:
print(math.type(5))print(math.type(6.3))print(math.type(-9))print(math.type("fugazzi"))
This results in the output:
integerfloatintegernil
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.