CodeToLive

Julia Variables & Data Types

Learn about variables, constants, and Julia's type system.

Variable Declaration

# Variable assignment
x = 10
name = "Julia"
pi_approx = 3.14159

# Constants (conventionally uppercase)
const SPEED_OF_LIGHT = 299792458

Basic Data Types

Type Example Description
Int 42 Integer (platform-dependent size)
Float64 3.14 64-bit floating point
Bool true, false Boolean value
Char 'J' Unicode character
String "Hello" UTF-8 encoded string

Type Conversion

x = 3.14
y = Int(x)  # 3 (truncates)

s = "123"
n = parse(Int, s)  # Convert string to integer

Type Annotations

# Variable with type annotation
x::Float64 = 3.14

# Function with type annotations
function add(a::Int, b::Int)::Int
    return a + b
end
← Back to Tutorials