How to find out a variable type in Julia

Variable type is necessary to understand to provide a valid value to that variable. In this answer, we'll learn how to get the type of a variable in Julia.

Julia provides a function typeof() to get the type of the variable.

Syntax

typeof(provide your variable name here)

Parameters and return value

This function takes a variable name as a parameter and returns its type.

Let's take a look at an example of this.

Example

var1 = 10
#display type of var1
println("Type of variable var1 is ", typeof(var1))
var2 = 10.5
#display type of var2
println("Type of variable var2 is ", typeof(var2))
var3 = "Hello from Educative !!!"
#display type of var3
println("Type of variable var3 is ", typeof(var3))
var4 = [1, 3, 5, 7, 9]
#display type of var4
println("Type of variable var4 is ", typeof(var4))

Explanation

  • Line 1: We declare and initialize a variable var1 with an integer value.

  • Line 4: We get the type of a variable var1 using the typeof() function.

  • Line 6: We declare and initialize a variable var2 with a float value.

  • Line 9: We get the type of a variable var2 using the typeof() function and display it.

  • Line 11: We declare and initialize a variable var3 with a string value.

  • Line 14: We get the type of a variable var3 using the typeof() function.

  • Line 16: We declare and initialize a variable var4 with a vector of integer value.

  • Line 19: We get the type of a variable var4 using the typeof() function and display it.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved