Choosing names and recognizing keywords

Syntax and values

An identifier is a name you choose for a variable or function. A keyword, such as if, already has a special job in the language and is reserved for that job. Case-sensitive means capital letters matter: score and Score are different names.

The technical character rules below let you use names from many languages and some emoji. ASCII is an older, small character set containing basic Latin letters, digits 0 through 9, and common punctuation. Unicode covers many more writing systems. Its category Other_Symbol includes pictorial symbols such as many emoji.

A combining mark adds something to a character, such as an accent. Emoji can also contain extra parts: a presentation selector asks for a text or colorful emoji appearance, a skin-tone modifier changes a person’s tone, and tag characters help specify certain flags. A zero-width joiner is an invisible link joining supported emoji parts into one displayed symbol. These are rules for recognizing the whole name; you do not need to type invisible characters yourself. Short, clear names such as score are a good starting point.

Identifiers are case-sensitive. They may start with _, a Unicode letter, or
a Unicode Other_Symbol character such as an ordinary emoji. Later characters
may also include Unicode decimal digits and combining marks.

Emoji presentation selectors, skin-tone modifiers, tag characters, and valid
zero-width-joiner emoji sequences remain part of the same identifier. A
zero-width joiner is accepted only between emoji symbol components; it cannot
act as an invisible separator in an ordinary identifier. An emoji sequence
whose first source character is an ASCII digit or # cannot start an
identifier because those characters retain their number and comment meanings.

Valid examples include:

score
player2
_temporary
café
🚀
score🚀
👩‍💻

An ASCII digit cannot start an identifier. Hyphens are subtraction operators,
not identifier characters, so use highScore or high_score, not
high-score.

English keywords are reserved and cannot be used as identifiers in English
source:

Keywords
use let set if
else while for in
function return when true
false none and or
not

Standard-library names such as say and forward are not keywords. They are
ordinary, shadowable names supplied by the selected locale.

Syntax and values · Built-ins · Programming guides