How do I create a getter and setter for variables?

Question

How do I create getters and setters for my variables in GDScript so that I can ensure that some code always runs when the value is gotten or set?

@export var foobar: Array = [] :
    get:
        return foobar
    set(value):
        foobar = value

History