What's the Definition of Operator in Computer Language?

By Xah Lee. Date: . Last updated: .

Operator is not well defined in programing languages. In math, we think of operators as notation for function. Typically, they have symbol forms, such as + - * / =.

[see What's Function, What's Operator?]

In programing languages, operator is not well defined.

in JavaScript, comma , is an operator, but not the comma in array.

js comma operator 2018 01 14 79472
JavaScript Comma Operator ECMAScript® 2016 Language Specification#sec-comma-operator

the equal character =, such as x = 4, is also an operator. But it could just be said as syntax.

Similarly, the new in new Date(), and delete in delete obj.key and typeof in typeof obj, and in in key in obj, are all considered as operators in JavaScript spec.

js assignment operator 2018 01 14 76649
JavaScript Assignment Operator ECMAScript® 2016 Language Specification#sec-assignment-operators
js new operator 2018 01 14 76244
JavaScript new Operator ECMAScript® 2016 Language Specification#sec-new-operator

The ternary if expression (test ? true_expr : false_expr), JavaScript calls it “conditional operator”.

js conditional operator 2018 01 14 24149
JavaScript Conditional Operator ECMAScript® 2016 Language Specification#sec-conditional-operator

However, the var in var x; is considered a statement.

js var statement 2018 01 14 7808
JavaScript var statement ECMAScript® 2016 Language Specification#sec-variable-statement

there does not seem to be a absolute definition that qualify something to be operator or just syntax or “statement”.

See also: JavaScript in Depth

Ask me question on patreon