Temporarily override variables in Emacs Lisp

In Emacs Lisp, the let expression is used to attach a symbol to a value, but only within the expression’s body:

(let ((my-variable "value"))
  my-variable)
value

The variable doesn’t exist outside of the expression body, so referencing it produces an error:

my-variable
Symbol's value as variable is void: my-variable

Overriding global variables

Let expressions can be used to temporarily override global variables. Given a variable exists named my-global-variable:

(set 'my-global-variable "value")
value

A let expression is used to temporarily override the global variable’s value:

(let ((my-global-variable "temporary value"))
  my-global-variable)
temporary value

Outside of the expression’s body, the variable is reverted to its original value:

my-global-variable
value