October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

JavaScript Operators: The Basics You Need to Know

Understand JavaScript operators through practical examples of grouping, comparisons, logical results, and choosing between ?? and ||.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

JavaScript operators act on values to form expressions. In const total = price * quantity + shipping;, multiplication happens before addition, so the expression means (price * quantity) + shipping. Parentheses can change that grouping—and make your intent easier to see.

What are JavaScript operators?

Operators are symbols or keywords that perform an operation on one or more values. The values they act on are operands, and the resulting combination is an expression. For example, in price * quantity, * is the operator and price and quantity are its operands.

As an Amazon Associate I earn from qualifying purchases.

Operators appear in several families. This overview covers common examples rather than every operator in the language.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Family Examples Typical purpose
Arithmetic + - * / % ** Calculate sums, differences, products, quotients, remainders, or powers.
Assignment = += and logical assignment operators Assign a value to a variable, sometimes combining assignment with another operation.
Comparison === !== < >= Compare values and produce a Boolean result.
Logical && || ! Combine conditions, select an operand based on truthiness, or negate a value.
Nullish coalescing ?? Use a fallback only when the left operand is null or undefined.
Conditional ? : Select one of two expressions based on a condition.
Optional chaining ?. Access a property or call a method only when the base value is not nullish.
Bitwise & | ^ and related operators Operate on numbers as binary representations; useful in specialized tasks, but not needed in every application.

How do precedence and parentheses affect an expression?

Precedence determines which operator binds more tightly when different operators appear together. In 3 + 10 * 2, multiplication has higher precedence than addition, so the result is 23. Written as (3 + 10) * 2, the parentheses make addition happen first and the result is 26.

In the total example, price * quantity + shipping multiplies the price and quantity before adding shipping. Writing (price * quantity) + shipping makes the grouping explicit, even though the parentheses do not change the result.

Associativity determines how operators of the same precedence group when there are no parentheses. Assignment is right-associative: a = b = 5 groups as a = (b = 5). First b receives 5; that assignment expression evaluates to 5, which is then assigned to a.

For exact precedence across JavaScript operators, consult MDN’s operator precedence reference. In everyday code, prefer parentheses when they make the intended grouping clearer than relying on a reader to recall the full precedence table.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What is the difference between === and ==?

=== compares without the type coercion associated with loose equality. For example, 5 === "5" is false because one operand is a number and the other is a string. By contrast, 5 == "5" is true: loose equality converts values in this comparison before checking them.

Use === and !== as the usual choices in beginner examples and ordinary application code; they make the type distinction visible. == and != are available, but use them deliberately when their coercion behavior is intended and understood.

Do && and || return true or false?

Not necessarily. Logical AND and OR short-circuit: they can skip evaluating the right operand, and their result can be one of the operands rather than a Boolean.

Logical AND

&& evaluates left to right. If its left operand is falsy, it returns that operand without evaluating the right side. Otherwise, it evaluates and returns the right operand. For example, "ready" && 7 evaluates to 7, while 0 && expensiveCheck() evaluates to 0 without calling expensiveCheck().

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Logical OR

|| also evaluates left to right. If its left operand is truthy, it returns that operand without evaluating the right side; otherwise it evaluates and returns the right operand. Thus "saved" || "new" evaluates to "saved", while "" || "new" evaluates to "new".

Guarding property access

A legacy-style guard such as user && user.name avoids reading name if user is falsy. When the intended nullish case should yield undefined, optional chaining is a clearer modern form: user?.name. If user is null or undefined, that access returns undefined and the chain short-circuits. Optional chaining can also guard method calls, as in user?.getName(). It is not valid as an assignment target, so user?.name = "Ari" is not allowed.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When should you use ?? instead of ||?

Use ?? when a fallback should apply only if the left value is null or undefined. For instance, const label = suppliedLabel ?? "Untitled"; preserves an empty string, 0, or false.

Use || when any falsy value should trigger the fallback. With const label = suppliedLabel || "Untitled";, an empty string, 0, or false selects "Untitled", as do null and undefined.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

JavaScript does not allow unparenthesized mixing of ?? with && or ||. For example, a ?? b || c is a syntax error. Add parentheses to state the intended grouping, such as (a ?? b) || c or a ?? (b || c); these expressions can behave differently, so choose the one that matches the logic you want.

For details on nullish coalescing and optional chaining, see MDN’s nullish coalescing reference and optional chaining reference. MDN also provides an overview of JavaScript expressions and operators.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.