THE BEST NEWSLETTER ANYWHERE
Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.
This short tutorials explains about how to get variable type.
typeof()
function accepts variable, and returns the variable datatype
Print the result to console using println
statement.
Here is an example
number = 11
println(typeof(number))
number1 = 11.12
println(typeof(number1))
name = "str"
println(typeof(name))
flag = false
println(typeof(flag))
println(typeof(Set([1,2,3])))
Output:
Int64
Float64
String
Bool
Set{Int64}
isa
operator checks an given variable or expresion is an given data type. This useful in conditional statement checking such as if else expressions.
variable/expression isa datatype
if an variable is given datatype, returns true,else false.
number = 11
if number isa Number
println("Given value is a Number")
else
println("Not a number")
end
🧮 Tags
Recent posts
Julia examples - Variable Type Nim example - Convert String to/from the Int How to get length of an array and sequence in Nim? Nim environment variables - read, set, delete, exists, and iterate examples? How to convert from single character to/from string in Nim?