Returns the type of a variable as a string. Use type() in Alibaba Cloud CDN EdgeScript to inspect variable types at runtime or write type-conditional logic.
type
Returns the type of its only argument as a string.
Syntax
type(s)Parameter
| Parameter | Type | Description |
|---|---|---|
s | Any | The variable to inspect. Accepts exactly one argument. |
Return value
A string indicating the type of s. The following table lists all possible return values.
| Return value | Type |
|---|---|
"string" | String |
"number" | Number |
"table" | Table (array or map) |
The return value is always of typestring, regardless of the type ofs.
Example
m = type('100') -- string literal: returns "string"
n = type(100) -- number literal: returns "number"
t = type(['a', 'b']) -- table literal: returns "table"
say(concat('type(m)=', m))
say(concat('type(n)=', n))
say(concat('type(t)=', t))Output:
type(m)=string
type(n)=number
type(t)=table