id | keywords | name | summary | category | ||
---|---|---|---|---|---|---|
ref-value-assignment |
|
:= |
This is the `ref value assignment` operator. |
operators |
This operator assigns a new value to a ref
.
<CodeTab labels={["ReScript", "JS Output"]}>
let total = ref(0)
total := 1
var total = {
contents: 0
};
total.contents = 1;
A ref
is a builtin record type with a mutable contents
field. Therefore the :=
operator is just a shorthand version for the following code:
<CodeTab labels={["ReScript", "JS Output"]}>
let total = ref(0)
total.contents = 1
var total = {
contents: 0
};
total.contents = 1;