Each symbol in code is an operator or a delimiter, and its meaning depends on the language: == compares values, && means "and", % gives a remainder and => defines a small function in JavaScript. This article explains what these symbols mean in coding, with an exact example for each in JavaScript or Python.
If you only need one symbol, scan the tables below. The sections after them cover the ones that cause the most confusion.
What an operator is
An operator is a symbol (or sometimes a keyword) that combines values into a new value. In 3 + 4, the + is the operator and 3 and 4 are its operands. A delimiter is a symbol that structures code rather than computing something, such as , between arguments or { } around a block.
The Python language reference puts it this way: operators are generally used to combine expressions, while delimiters serve other purposes, but there is no clear, formal distinction between the two. Some tokens do both. For example, * is multiplication and also a delimiter for unpacking a sequence, and @ is matrix multiplication and also the symbol that introduces a decorator.
Comparison and logic symbols in JavaScript
| Symbol | Name | Example | Result |
|---|---|---|---|
== | Equality | "1" == 1 | true (converts types first) |
=== | Strict equality | "1" === 1 | false (different types) |
!= and !== | Inequality, strict inequality | 3 !== 4 | true |
&& | Logical AND | a && b | Evaluates b only if a is truthy |
|| | Logical OR | a || b | Evaluates b only if a is falsy |
! | Logical NOT | !true | false |
?? | Nullish coalescing | 0 ?? 42 | 0 |
?. | Optional chaining | user?.name | undefined if user is nullish |
? : | Conditional (ternary) | n > 0 ? "pos" : "neg" | One of the two values |
== versus ===
MDN states that strict equality "always considers operands of different types to be different", while == tries to convert the operands to the same type before comparing. Strict equality also says two objects are equal only if they are the same object, and that anything compared with NaN is false. Use === by default so a string never silently equals a number.
"hello" === "hello"; // true
"3" === 3; // false
null === undefined; // false
const a = { key: "value" };
const b = { key: "value" };
a === b; // false (different objects)
a === a; // true (same object)
?? versus ||
Both pick a fallback value, but they decide differently. || uses the right side when the left is any falsy value, including 0 and the empty string. ?? uses the right side only when the left is null or undefined. This matters for values like a quantity of zero.
const count = 0;
console.log(count || 42); // 42, the 0 was thrown away
console.log(count ?? 42); // 0, the 0 was kept
Like && and ||, ?? short-circuits: if the left side is neither null nor undefined, the right side is never evaluated. For a deeper look at the three-part ? : form, see the JavaScript ternary operator explained.
The ?. symbol
Optional chaining returns undefined instead of throwing an error when the reference before it is null or undefined.
const user = null;
console.log(user?.profile); // undefined, no TypeError
The => symbol (arrow functions)
In JavaScript, => is not an operator. MDN calls it the notation for arrow functions, "a compact alternative to a traditional function expression". The parameters go on the left and the body on the right.
const add = (a, b) => a + b;
// same as: function (a, b) { return a + b; }
Arrow functions have no this of their own; they use the this of the scope they were written in. They cannot be called with new: new Foo() on an arrow function throws TypeError: Foo is not a constructor. One trap: to return an object literal from a short body, wrap it in parentheses, because bare braces are read as a block.
const wrong = () => { foo: 1 }; // returns undefined
const right = () => ({ foo: 1 }); // returns { foo: 1 }
Math symbols that surprise beginners
| Symbol | Language | Meaning | Example |
|---|---|---|---|
% | JavaScript, Python | Remainder after division | Python 7 % 3 is 1 |
// | Python | Floor division | 7 // 2 is 3 |
** | JavaScript, Python | Exponentiation | 2 ** 3 is 8 |
@ | Python | Matrix multiplication, and decorator marker | a @ b |
:= | Python | Assignment expression ("walrus") | if (n := len(x)) > 3: |
% is a remainder, not a percentage
In both languages % gives what is left after dividing. Python's reference says the result has the same sign as the second operand, and ties it to floor division with the identity x == (x//y)*y + (x%y).
7 // 2 # 3
-7 // 2 # -4 (rounds down, not toward zero)
7 % 3 # 1
-7 % 3 # 2 (same sign as the divisor)
Python's // divides and rounds down to the nearest whole number, while / always returns a float for integers (7 / 2 is 3.5). In JavaScript, // starts a comment, so it does not divide at all. More examples are in Python operators explained.
** and the minus sign
Python documents that -1 ** 2 is -1, because ** binds tighter than the unary minus, so it is read as -(1 ** 2). Write (-1) ** 2 to get 1. Python also notes that 10 ** 2 is 100 but 10 ** -2 is 0.01. JavaScript is stricter: an unparenthesised negative base before ** is a syntax error.
:= and @ in Python
The Python docs describe := as assigning a value to a name while also returning it. That lets you test and keep a value in one step:
while chunk := file.read(9000):
process(chunk)
The same page says the @ operator is intended for matrix multiplication and that no built-in Python type implements it. Libraries such as NumPy define it for their own types. In front of a function name, @ is a decorator instead.
Python's word operators
Some Python operators are words, not symbols. The lexical reference lists and, or and not in as keyword tokens. Python has no && or || for logic; those characters never appear in its operator list as logical operators. Instead:
and,or,notcombine conditions.inandnot intest membership:2 in [1, 2, 3]isTrue, and for a dictionary it tests keys.isandis nottest identity, meaning the same object, not equal values. UseisforNoneand==for values. CPython warns aboutx is 7withSyntaxWarning: "is" with 'int' literal. Did you mean "=="?
Symbols that mean nothing in a language
A symbol that is valid in one language can be an error in another. The Python reference lists the question mark, the dollar sign and the backquote as errors when they appear outside string literals and comments. So ?:, ?? and ?. from JavaScript do not exist in Python; Python spells the conditional form x if condition else y. The same applies the other way: JavaScript has no // floor division and no @ operator.
How to look up an unknown symbol
- Name the language first. The same characters mean different things in JavaScript, Python and C.
- Find the operator list in the official reference: MDN's "Expressions and operators" page for JavaScript, or "Lexical analysis" and "Expressions" in the Python language reference.
- Check the context. A
*indef f(*args)collects arguments, but ina * bit multiplies. A:can start a block, separate a dictionary key from its value, or be half of a ternary. - Try it in a REPL: run
nodeorpythonin a terminal and type the expression to see the real result.
Bit-level symbols such as &, |, ^, ~, << and >> are a separate topic. Bitwise operators in C with examples covers them.
If a symbol still doesn't make sense
Look at which of three roles it plays: arithmetic or comparison (it produces a value), logic (it chooses between values), or structure (it groups or separates code). If it appears right after a name and before parentheses, it is probably a decorator or a call modifier. If it appears in a string, it is just text. When two readings are possible, the surrounding syntax and the language reference decide, not the symbol alone.
Frequently asked questions
- Is == the same as = in code?
- No. A single = assigns a value to a variable. A double == compares two values and gives true or false. Mixing them up is a classic bug, for example writing = inside an if condition in languages that allow it.
- Why does the same symbol mean different things in different languages?
- Each language defines its own grammar. The % symbol is a remainder operator in both JavaScript and Python, but @ is a decorator and matrix-multiplication symbol in Python and means nothing as an operator in JavaScript. Always check the reference for the language you are using.
- What does ? mean in code?
- It depends on where it appears. In JavaScript, ?: is the conditional (ternary) operator, ?. is optional chaining and ?? is nullish coalescing. In Python, a bare question mark is an error outside strings and comments.
- What is the difference between an operator and a delimiter?
- Operators combine expressions, like + or and. Delimiters serve other purposes, like commas and brackets. The Python reference says there is no clear formal distinction, and some tokens act as both.