Comp Lang: What is the Definition of Operator
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 is Function, What is Operator. (2010)〕
In programing languages, operator is not well defined.
- Sometimes they are English words, not symbol. e.g. JavaScript's
typeofandnew,in. - But sometimes such word is called “keyword” and not operator, e.g. JavaScript
super. - Some operators, have different meaning depending on neighboring context, e.g. JavaScript's comma, and the
inoperator. 〔see JavaScript Context Dependent Semantics: p in o〕 - Sometimes a operator-like symbol is not called a operator, but just part of syntax, e.g. JavaScript square bracket for array
[3,4,5]or property accesscolor[blue]. - Sometimes, the operator does not have a function form or is not a function at all, unlike the math sense.
in JavaScript, comma , is an operator, but not the comma in array.
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.
new Operator.
ECMAScript® 2016 Language Specification, 12.3.3
The if-expression of ternary operator
(test ? true_expr : false_expr)
, JavaScript calls it “conditional operator”.
However, the var in var x; is considered a 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
Programing Language Operators
- What is Function, What is Operator. (2010)
- Programing Language Design: Why You Need Operators
- Comp Lang: What is the Definition of Operator
- Comp Lang: Necessity of Operator Overload
- Which Programing Languages Allow Unicode Math Symbols in Function Name and Operator
- Logical Operators, Truth Table, Unicode (2010)