官术网_书友最值得收藏!

  • Phoenix Web Development
  • Brandon Richey
  • 142字
  • 2021-08-27 18:28:21

Variables in Elixir

Like most other programming languages, Elixir has a concept of variables. Variables are, simply put, just a place to store values or data. Variables in Elixir do not require any sort of type definition or declaration that they're variables, as you might see in languages such as JavaScript. We can declare a new variable as simply as follows:

iex(1)> greeting = "Hello There"
"Hello There"
In IEx, the output of any statement entered is always the next line in the shell.

Variables point to memory locations, so when you use them in your code, the values stored in those memory locations are automatically pulled out for you, as shown in the following example:

iex(2)> greeting
"Hello There"

While variables can be reassigned in Elixir, the actual values are immutable! This brings us to our first gotcha in Elixir: immutability.

主站蜘蛛池模板: 峨山| 孝感市| 巴南区| 景宁| 阳东县| 马尔康县| 年辖:市辖区| 旌德县| 永春县| 昔阳县| 罗平县| 三门峡市| 依安县| 定结县| 东光县| 连平县| 屏山县| 建昌县| 普定县| 林甸县| 沂水县| 松桃| 邳州市| 闽侯县| 宣汉县| 尖扎县| 阳曲县| 双城市| 庆元县| 梁河县| 外汇| 保定市| 南汇区| 牡丹江市| 高淳县| 阿巴嘎旗| 东港市| 游戏| 搜索| 雅安市| 当涂县|