Google News
logo
Elixir - Interview Questions
Explain what types of variables are available in Elixir
In Elixir, there are several types of variables that can be used to store and manipulate data. Here are the most commonly used variable types in Elixir:

* Atoms : Atoms are constants that represent their own name. They are identified by a leading colon (`:`) followed by a sequence of characters or symbols. Atoms are often used as identifiers, flags, or keys in maps. Examples of atoms in Elixir are `:ok`, `:error`, or `:name`.

* Numbers : Elixir supports several numeric types, including integers and floats. Integers can be written using standard decimal notation, as well as hexadecimal (prefixed with `0x`), octal (prefixed with `0o`), and binary (prefixed with `0b`) notations. Floats represent fractional or floating-point numbers, such as `3.14` or `1.0e-6`.

* Booleans : Booleans represent logical values and can have two possible states: `true` or `false`. Booleans are commonly used in conditional statements and logical operations.

* Strings : Strings represent sequences of characters and are enclosed in double quotes (`"`). Elixir supports Unicode strings, allowing you to work with text in various languages and character sets. String interpolation is also available using the `#{}` syntax to embed variables within a string.

* Immutable Variables : Elixir variables are immutable by default, meaning that once assigned a value, they cannot be changed. When you assign a new value to a variable, it actually creates a new variable binding rather than modifying the existing value. Immutable variables promote functional programming principles and help ensure code reliability.
Advertisement