RuneHub
Tech Trends
RuneAI
RuneHub
Programming Education Platform

Master programming through interactive tutorials, hands-on projects, and personalized learning paths designed for every skill level.

Stay Updated

Learning Tracks

  • Programming Languages
  • Web Development
  • Data Structures & Algorithms
  • Backend Development

Practice

  • Interview Prep
  • Interactive Quizzes
  • Flashcards
  • Learning Roadmaps

Resources

  • Tutorials
  • Tech Trends
  • Search
  • RuneAI

Support

  • FAQ
  • About Us
  • Privacy Policy
  • Terms of Service
  • System Status
© 2026 RuneAI. All rights reserved.
RuneHub
Tech Trends
RuneAI
RuneHub
Programming Education Platform

Master programming through interactive tutorials, hands-on projects, and personalized learning paths designed for every skill level.

Stay Updated

Learning Tracks

  • Programming Languages
  • Web Development
  • Data Structures & Algorithms
  • Backend Development

Practice

  • Interview Prep
  • Interactive Quizzes
  • Flashcards
  • Learning Roadmaps

Resources

  • Tutorials
  • Tech Trends
  • Search
  • RuneAI

Support

  • FAQ
  • About Us
  • Privacy Policy
  • Terms of Service
  • System Status
© 2026 RuneAI. All rights reserved.
RuneHub
Tech Trends
RuneAI
RuneHub
Programming Education Platform

Master programming through interactive tutorials, hands-on projects, and personalized learning paths designed for every skill level.

Stay Updated

Learning Tracks

  • Programming Languages
  • Web Development
  • Data Structures & Algorithms
  • Backend Development

Practice

  • Interview Prep
  • Interactive Quizzes
  • Flashcards
  • Learning Roadmaps

Resources

  • Tutorials
  • Tech Trends
  • Search
  • RuneAI

Support

  • FAQ
  • About Us
  • Privacy Policy
  • Terms of Service
  • System Status
© 2026 RuneAI. All rights reserved.
RuneHub
Tech Trends
RuneAI

Programming Languages

1 topic · 323 articles

    • What is JavaScript? A Complete Beginner Guide
    • What is JavaScript Used For in Web Development
    • Is JavaScript Frontend or Backend? Full Guide
    • JavaScript vs Java: Core Differences Explained
    • How to Start Coding in JavaScript for Beginners
    • The Complete History of JavaScript Explained
    • Who Invented JavaScript? The Brendan Eich Story
    • How JavaScript Evolved from ES1 to Modern ES6+
    • The History of ECMAScript and JavaScript Guide
    • How JavaScript Works in the Browser Explained
    • What is a JavaScript Engine? A Complete Guide
    • How Browsers Read and Execute JavaScript Code
    • How to Run JavaScript in the Browser and Node
    • How to Execute JavaScript in Chrome DevTools
    • Deploying JS Apps Free with GitHub Student Plan
    • JS Variables Guide: How to Declare and Use Them
    • JavaScript Variable Naming Conventions & Rules
    • Global vs Local Variables in JavaScript Guide
    • var vs let vs const: JS Variable Declarations
    • Why You Should Stop Using var in JavaScript
    • When to Use let vs const in Modern JavaScript
    • JavaScript Data Types: A Complete Beginner Guide
    • What are Dynamic Data Types in JavaScript?
    • Primitive vs Reference Types in JS: Full Guide
    • How JavaScript Stores Primitive Values in Memory
    • JavaScript Type Conversion & Coercion Explained
    • JavaScript Implicit vs Explicit Type Conversion
    • Guide to JavaScript Template Literals & Strings
    • Creating Multi-Line Strings in JS With Backticks
    • JS Operators: Arithmetic, Logical & Comparison
    • JavaScript Operator Precedence: Complete Guide with Examples
    • How to Use the typeof Operator in JavaScript: Full Guide
    • What is NaN in JavaScript? A Complete Not a Number Guide
    • How to Check for NaN in JavaScript Using isNaN() Function
    • Undefined vs Null in JavaScript: Key Differences Explained
    • Why You Should Never Assign Undefined in JavaScript Code
    • How to Write Single and Multi-Line Comments in JavaScript
    • JavaScript Commenting Best Practices Every Coder Should Know
    • JavaScript Semicolons: Are They Required? A Complete Guide
    • Automatic Semicolon Insertion (ASI) in JavaScript Explained
    • JavaScript Strict Mode ('use strict') Explained
    • Common Errors Caught by JavaScript Strict Mode
    • JavaScript Console Methods: log, warn & errors
    • Grouping Logs Together with console.group() JS
    • Basic JavaScript Debugging Tips for Beginners
    • How to Read and Understand JavaScript Stack Traces
    • JavaScript If Statement: A Complete Beginner Guide
    • How to Write If Else Statements in JS: Full Guide
    • JavaScript Else If: Chaining Multiple Conditions
    • JS Switch Statement vs If Else: Which is Better?
    • How to Use the JavaScript Switch Case Full Guide
    • JavaScript Ternary Operator: Complete Syntax Guide
    • Chaining Ternary Operators in JavaScript Tutorial
    • JS For Loop Syntax: A Complete Guide for Beginners
    • How to Loop Through Arrays using JS For Loops Guide
    • JavaScript While Loop Explained: A Complete Guide
    • How to Avoid Infinite Loops in JS: Full Tutorial
    • JS Do-While Loop: Syntax and Practical Use Cases
    • JavaScript Break Statement: Exiting Loops Early
    • JavaScript Continue Statement: Skipping Iterations
    • How to Write Nested Loops in JavaScript: Tutorial
    • Optimizing JavaScript Loops for Fast Performance
    • What are Truthy and Falsy Values in JavaScript?
    • JavaScript Logical Short-Circuiting Complete Guide
    • What is a Function in JavaScript? Beginner Guide
    • How to Declare and Call a JavaScript Function
    • JavaScript Function Expressions vs Declarations
    • JavaScript Arrow Functions: A Complete ES6 Guide
    • When to Avoid Using Arrow Functions in JavaScript
    • JS Function Parameters vs Arguments: Differences
    • How to Use Default Parameters in JS Functions
    • JavaScript Rest Parameters: A Complete Tutorial
    • What is a Callback Function in JS? Full Tutorial
    • How to Pass a Function as an Argument in JS Guide
    • Pure vs Impure Functions in JavaScript Explained
    • Writing Pure Functions in JS: A Complete Tutorial
    • JavaScript IIFE: Immediately Invoked Functions
    • How to Use Recursion in JavaScript: Full Tutorial
    • Preventing Stack Overflow in JavaScript Recursion
    • Higher-Order Functions in JavaScript: Full Guide
    • Returning Functions from Functions in JavaScript
    • JavaScript Function Scope: Local vs Global Scope
    • Understanding JavaScript Hoisting for Beginners
    • JavaScript Execution Context: A Complete Tutorial
    • What is an Array in JavaScript? A Complete Guide
    • How to Create and Initialize JavaScript Arrays
    • Accessing and Modifying JS Array Elements Guide
    • JS Array Push and Pop Methods: A Complete Guide
    • JS Array Shift and Unshift Methods: Full Tutorial
    • JavaScript Array Slice Method: A Complete Guide
    • JavaScript Array Splice Method: Complete Tutorial
    • JS Array Slice vs Splice: What is the Difference?
    • How to Use the JavaScript Array Map Method Today
    • JavaScript Array Filter Method: Complete Tutorial
    • Using the JavaScript Array Reduce Method Guide
    • JavaScript Array forEach Loop: Complete Tutorial
    • JS Array Map vs forEach: Which Should You Use?
    • JavaScript Array Find and findIndex Methods Guide
    • JS Array Some and Every Methods: Complete Guide
    • How to Sort Arrays in JavaScript: Complete Guide
    • Sorting Numbers Correctly in JS Arrays Tutorial
    • JS Array Flat Method: Flatten Nested Arrays Fast
    • JavaScript Array flatMap Method: Complete Guide
    • JavaScript Array Destructuring: Complete Tutorial
    • JavaScript Functions Explained: From Basic to Advanced Concepts
    • JavaScript Loops Tutorial: for, while & do-while
    • JavaScript Conditional Statements: if, else & switch Guide
    • Learn JavaScript Step by Step Tutorial with Real Examples
    • JavaScript Objects & Arrays: Complete Tutorial
    • JS Spread Operator for Arrays: Complete Tutorial
    • How to Merge Two Arrays in JavaScript Full Guide
    • Removing Duplicates from JavaScript Arrays Guide
    • Top JS Array Methods Interview Questions to Know
    • What is an Object in JavaScript? Beginner Guide
    • How to Create Objects in JavaScript: Full Guide
    • Accessing Object Properties in JS: Full Tutorial
    • JS Objects: Dot Notation vs Bracket Notation
    • Adding and Deleting Properties in JS Objects
    • JavaScript Object Methods: A Complete Tutorial
    • The 'this' Keyword in JavaScript Objects Guide
    • JavaScript Object Destructuring Complete Guide
    • Renaming Variables in JS Object Destructuring
    • How to Use Object.assign in JavaScript Properly
    • JS Object Keys, Values, and Entries Full Guide
    • How to Loop Through a JavaScript Object Tutorial
    • JS Optional Chaining (?.) Syntax Complete Guide
    • JS Nullish Coalescing Operator (??) Full Guide
    • How to Clone a JavaScript Object Without Errors
    • Shallow Copy vs Deep Copy in JavaScript Objects
    • What is the DOM in JavaScript? A Beginner Guide
    • Understanding the HTML DOM Tree Structure Guide
    • Selecting DOM Elements in JavaScript Full Guide
    • How to Use JS querySelector and querySelectorAll
    • How to Use getElementById in JS: Complete Guide
    • JS getElementsByClassName vs querySelector Guide
    • How to Change Text Content Using JavaScript DOM
    • innerText vs textContent in JavaScript Explained
    • Using innerHTML Safely in JavaScript DOM Methods
    • Changing CSS Styles with JavaScript DOM Methods
    • Building Beautiful JS UIs with Inter & Outfit
    • Adding and Removing CSS Classes with JavaScript
    • How to Use classList toggle in JavaScript DOM
    • Creating HTML Elements with JavaScript DOM Guide
    • Appending Elements to the DOM in JS: Full Guide
    • Removing HTML Elements Using JavaScript Methods
    • How to Add Event Listeners in JS: Complete Guide
    • Handling Click Events in JavaScript: Full Guide
    • JavaScript Keyboard Events: keyup and keydown
    • JavaScript Event Bubbling Explained for Beginners
    • JavaScript Event Delegation: Complete Tutorial
    • Using preventDefault() in JavaScript Full Guide
    • JavaScript Form Handling and Submission Tutorial
    • Basic Form Validation with JavaScript Tutorial
    • Build a JavaScript Todo App: Beginner DOM Project
    • Build a JS Counter App: Beginner DOM Mini Project
    • Build a JS Calculator: Beginner DOM Mini Project
    • JavaScript Closures Deep Dive: Complete Guide
    • Practical Use Cases for JS Closures in Real Apps
    • How to Prevent Memory Leaks in JavaScript Closures
    • JavaScript Lexical Scope: A Complete Tutorial
    • How Lexical Environment Works in JavaScript
    • JS Execution Context Deep Dive: Full Tutorial
    • Understanding the JavaScript Call Stack Guide
    • How the JS Call Stack Handles Function Execution
    • JavaScript setTimeout Behavior: Complete Guide
    • How setInterval Works in JavaScript: Architecture
    • Clearing Timeouts and Intervals in JavaScript
    • The JavaScript Event Loop Explained in Detail
    • JS Microtasks vs Macrotasks: A Complete Guide
    • JavaScript Callbacks vs Promises: Full Tutorial
    • Avoiding Callback Hell in JavaScript: Complete Tutorial
    • JavaScript Promise Chaining: A Complete Guide
    • How to Handle Promise Rejections in JavaScript
    • How to Use Promise.all in JavaScript: Complete Tutorial
    • Using Promise.allSettled for Reliable JavaScript APIs
    • How to Use Promise.race in JavaScript: Complete Guide
    • JavaScript async/await: Complete Tutorial Guide
    • Converting Promises to async/await in JavaScript
    • JavaScript try/catch Tutorial: Advanced Error Handling
    • Handling Async Errors With try/catch in JavaScript
    • Creating Custom Errors in JavaScript: Complete Tutorial
    • Extending the JavaScript Error Class: Full Guide
    • The JavaScript Prototype Chain: Complete Guide
    • JavaScript __proto__ vs prototype: What Is the Difference?
    • How Prototypal Inheritance Works in JavaScript
    • Modifying the JavaScript Object Prototype: Guide
    • JS Constructor Functions: A Complete Tutorial
    • JavaScript Classes Explained: Complete Tutorial
    • JavaScript Class Inheritance: Complete Tutorial
    • Using the super Keyword in JavaScript Classes
    • JavaScript Static Methods: A Complete Tutorial
    • Encapsulation in JavaScript: Complete Tutorial
    • Creating Private Class Fields in Modern JS
    • Polymorphism in JavaScript: Complete Tutorial
    • The JavaScript this Keyword: Full Deep Dive
    • How Arrow Functions Change this in JavaScript
    • Losing this in JavaScript Callbacks Explained
    • JS bind, call, and apply Methods: Full Tutorial
    • When to Use JS bind vs call vs apply: Full Guide
    • JS let vs const: An Advanced Memory Deep Dive
    • Advanced Arrow Functions in JS: Complete Guide
    • Returning Objects from JS Arrow Functions Guide
    • Advanced Array and Object Destructuring Guide
    • Renaming Variables During JS Destructuring Guide
    • JS Spread vs Rest Operator Complete Tutorial
    • Copying Nested Objects With the JS Spread Operator
    • JavaScript ES6 Modules Import Export Guide
    • JavaScript Default Exports Complete Tutorial
    • JavaScript Named Exports a Complete Tutorial
    • Dynamic Imports in JavaScript Complete Guide
    • Advanced JS Optional Chaining Complete Guide
    • Advanced JS Nullish Coalescing Full Tutorial
    • Logical Assignment Operators in JS Complete Guide
    • Deploying JS Modules Using the GitHub Student Plan
    • JavaScript Tagged Template Literals Deep Dive
    • Building Custom JS String Parsers Full Tutorial
    • The JS Event Loop Architecture Complete Guide
    • Browser Web APIs in JavaScript Complete Guide
    • How to Use the JS Fetch API Complete Tutorial
    • Handling POST Requests With JS Fetch API Guide
    • Uploading Files via JS Fetch API Complete Guide
    • Building a Dynamic JS Portfolio at Parthh.in
    • How to Use Axios in JavaScript: Complete Guide
    • Axios Interceptors in JavaScript: Complete Guide
    • Advanced API Error Handling in JS: Full Guide
    • Debouncing in JavaScript: A Complete Tutorial
    • Building a Search Bar with JS Debouncing Guide
    • Throttling in JavaScript: A Complete Tutorial
    • Scroll Event Throttling in JavaScript: Full Guide
    • Rate Limiting in JavaScript: Complete Tutorial
    • Advanced JS Promise Patterns: Complete Tutorial
    • API Retry Patterns in JavaScript: Full Tutorial
    • Using AbortController in JS: Complete Tutorial
    • Canceling Fetch Requests in JavaScript Full Guide
    • JavaScript Web Streams API: A Complete Tutorial
    • JavaScript Async Generators: Complete Tutorial
    • JS LocalStorage API Guide: A Complete Tutorial
    • Storing Complex Objects in JS LocalStorage Guide
    • JS SessionStorage API Guide: Complete Tutorial
    • How to Manage Cookies in JS: Complete Tutorial
    • Parsing and Deleting Browser Cookies With JS
    • JS Geolocation API Guide: A Complete Tutorial
    • Tracking User Location With JavaScript Geolocation
    • JavaScript Clipboard API: A Complete Tutorial
    • Building a Copy to Clipboard Button in JavaScript
    • JavaScript History API Guide: Complete Tutorial
    • Creating an SPA Router With the JS History API
    • JS Intersection Observer API: Complete Tutorial
    • Implementing Infinite Scroll with JS Observers
    • JavaScript Mutation Observer: Complete Tutorial
    • Tracking DOM Changes with JS Mutation Observers
    • JavaScript Notifications API: Complete Tutorial
    • Requesting Desktop Notification Permissions in JS
    • The Web Storage API: Local vs Session Storage
    • Using the Web Audio API in JavaScript Full Guide
    • Fixing JavaScript Memory Leaks: Complete Guide
    • How to Find and Fix Memory Leaks in JavaScript
    • Identifying Detached DOM Elements in JavaScript
    • JavaScript Garbage Collection Complete Guide
    • How V8 Garbage Collector Works in JavaScript
    • Mark-and-Sweep Algorithm in JS: Full Tutorial
    • JavaScript Profiling: Advanced Performance Guide
    • Using Chrome DevTools for JS Performance Tuning
    • How to Measure JavaScript Execution Time Accurately
    • JS Code Splitting: Advanced Performance Guide
    • Implementing Route-Level Code Splitting in JS
    • Lazy Loading in JavaScript: Complete Tutorial
    • How to Lazy Load Images and Components in JS
    • JavaScript Tree Shaking: A Complete Tutorial
    • Removing Dead Code with JS Tree Shaking Guide
    • JavaScript Bundlers: An Advanced Architecture
    • Webpack vs Vite vs Rollup: JS Bundler Guide
    • Optimizing JavaScript for Core Web Vitals Guide
    • Minifying and Uglifying JavaScript Code for Production
    • JavaScript Module Pattern: Advanced Tutorial
    • Implementing the Revealing Module Pattern JS
    • JavaScript Singleton Pattern: Complete Guide
    • When to Use the Singleton Pattern in JS Apps
    • JavaScript Observer Pattern: Complete Guide
    • Building a Reactive UI with the JS Observer
    • The JavaScript Factory Pattern: Complete Guide
    • Creating Dynamic Objects with JS Factory Pattern
    • JavaScript Strategy Pattern: Complete Guide
    • The JavaScript Proxy Pattern: Complete Guide
    • JavaScript Decorator Pattern: Complete Guide
    • Using Decorators for Logging in JS Architecture
    • The JavaScript Pub/Sub Pattern: Complete Guide
    • Building an Event Bus with JS Pub/Sub Pattern
    • JavaScript MVC Architecture: Complete Guide
    • Building Vanilla JS Apps with MVC Architecture
    • Vanilla JS State Management for Advanced Apps
    • Building Enterprise UI Systems in Vanilla JS
    • JavaScript V8 Engine Internals: Complete Guide
    • How the Google V8 Engine Compiles JavaScript
    • JavaScript Parsing and Compilation: Full Guide
    • Abstract Syntax Trees (AST) in JavaScript Guide
    • V8 Hidden Classes in JavaScript: Full Tutorial
    • Optimizing JS Object Creation for V8 Engine
    • JavaScript Inline Caching: A Complete Tutorial
    • JavaScript Bytecode Explained: Complete Guide
    • Ignition Interpreter and JS Bytecode Tutorial
    • JavaScript JIT Compilation Advanced Tutorial
    • TurboFan Compiler and JS Optimization Guide
    • JavaScript Event Loop Internals Full Guide
    • Understanding libuv and JS Asynchronous I/O
    • Call Stack vs Task Queue vs Microtask Queue in JS
    • Advanced JavaScript Proxies Complete Guide
    • Data Binding with JS Proxies Complete Guide
    • Intercepting Object Calls with JS Proxy Traps
    • JavaScript Reflect API Advanced Architecture
    • Using Reflect and Proxy Together in JavaScript
    • JavaScript WeakMap and WeakSet Complete Guide
    • Preventing Memory Leaks with JS WeakMaps Guide
    • JavaScript Generators Deep Dive Full Guide
    • Handling Async Flows with JS Generator Functions
    • Advanced JavaScript Iterators Complete Guide
    • Creating JavaScript Custom Iterables Full Guide
    • JS Metaprogramming Advanced Architecture Guide
    • Writing Self-Modifying Code in JS Architecture
    • Creating Advanced UI Frameworks in JavaScript
    • JavaScript Macros and Abstract Code Generation
    • Advanced Web Workers for High Performance JS
    • OffscreenCanvas API in JS for UI Performance
Previous
JS Operators: Arithmetic, Logical & Comparison
13 min · beginner
Next
How to Use the typeof Operator in JavaScript: Full Guide
11 min · beginner
Home/Tutorials/Programming Languages/JavaScript

JavaScript Operator Precedence: Complete Guide with Examples

Learn how JavaScript operator precedence determines the order of operations in expressions. Master grouping, associativity, and evaluation rules with practical code examples.

JavaScriptbeginner
RuneHub Team
RuneHub Team
February 25, 2026
10 min read
RuneHub Team
RuneHub Team
Feb 25, 2026
10 min read

JavaScript operator precedence determines which parts of an expression get evaluated first when multiple operators appear in the same statement. If you have ever written a calculation that returned an unexpected result, the answer almost always traces back to precedence rules.

Think of operator precedence like the order of operations you learned in math class. Multiplication happens before addition, parentheses override everything, and there is a specific pecking order that the JavaScript engine follows every single time. Understanding this pecking order is the difference between expressions that work correctly and subtle bugs that take hours to track down.

This guide walks you through every precedence level that matters in daily JavaScript development, with real code examples that demonstrate exactly how the engine evaluates each expression.

What is Operator Precedence in JavaScript?

Operator precedence is a set of rules that the JavaScript engine uses to decide which operator in an expression executes first. When an expression contains multiple operators, the engine does not simply read left to right. Instead, it consults a precedence table and evaluates higher-precedence operators before lower-precedence ones.

javascriptjavascript
// Without knowing precedence, what does this return?
const result = 2 + 3 * 4;
console.log(result); // 14, not 20
 
// The engine evaluates 3 * 4 first (precedence 13)
// Then evaluates 2 + 12 (precedence 12)

The ECMAScript specification defines 19 precedence levels, numbered from 1 (lowest) to 19 (highest). Operators with higher precedence numbers execute before operators with lower numbers.

Why Precedence Matters for Real Code

Precedence is not just an academic concept. It directly affects real code decisions:

javascriptjavascript
// Bug: developer intended to check if user is active AND has admin role
const hasAccess = isActive || isAdmin && hasPermission;
// Actually evaluates as: isActive || (isAdmin && hasPermission)
// Because && has higher precedence than ||
 
// Fix: use explicit parentheses
const hasAccess = (isActive || isAdmin) && hasPermission;

The JavaScript Operator Precedence Table

Here is a practical reference table covering the operators you will encounter most frequently. Higher numbers mean the operator executes first.

PrecedenceOperatorDescriptionAssociativity
19()Grouping (parentheses)N/A
18. [] () ?.Member access, computed access, function call, optional chainingLeft-to-right
17new (with args)Constructor callN/A
16++ -- (postfix)Postfix increment/decrementN/A
15! ~ typeof void delete ++ -- (prefix)Unary operatorsRight-to-left
14**ExponentiationRight-to-left
13* / %Multiplication, division, remainderLeft-to-right
12+ -Addition, subtractionLeft-to-right
11<< >> >>>Bitwise shiftLeft-to-right
10< <= > >= in instanceofRelationalLeft-to-right
9== != === !==EqualityLeft-to-right
8&Bitwise ANDLeft-to-right
7^Bitwise XORLeft-to-right
6|Bitwise ORLeft-to-right
5&&Logical ANDLeft-to-right
4|| ??Logical OR, Nullish coalescingLeft-to-right
3? :Ternary conditionalRight-to-left
2= += -= *= etc.AssignmentRight-to-left
1,CommaLeft-to-right

Understanding Associativity

When two operators share the same precedence level, associativity determines the evaluation direction. Left-to-right associativity means the leftmost operator executes first. Right-to-left means the rightmost goes first.

javascriptjavascript
// Left-to-right associativity (subtraction, precedence 12)
const result = 10 - 5 - 2;
// Evaluates as: (10 - 5) - 2 = 3
// NOT as: 10 - (5 - 2) = 7
 
console.log(result); // 3
javascriptjavascript
// Right-to-left associativity (assignment, precedence 2)
let a, b, c;
a = b = c = 10;
// Evaluates as: a = (b = (c = 10))
// c gets 10, then b gets 10, then a gets 10
 
console.log(a, b, c); // 10 10 10

Exponentiation is Right-to-Left

The exponentiation operator (**) is one of the few arithmetic operators with right-to-left associativity:

javascriptjavascript
const result = 2 ** 3 ** 2;
// Evaluates as: 2 ** (3 ** 2) = 2 ** 9 = 512
// NOT as: (2 ** 3) ** 2 = 8 ** 2 = 64
 
console.log(result); // 512

Grouping with Parentheses (Precedence 19)

Parentheses have the highest precedence level in JavaScript. They override every other precedence rule, making them your most reliable tool for controlling evaluation order.

javascriptjavascript
// Without parentheses
const price = 100 + 50 * 0.1;
console.log(price); // 105 (50 * 0.1 happens first)
 
// With parentheses to calculate total first
const discountedPrice = (100 + 50) * 0.1;
console.log(discountedPrice); // 15 (100 + 50 happens first)
When in Doubt, Use Parentheses

Even when you know the precedence rules, adding parentheses makes your intent explicit to other developers reading your code. Readable code is more valuable than clever code. A team member who has to look up the precedence table to understand your expression is a team member who might introduce a bug during a quick edit.

Nested Parentheses

Nested parentheses evaluate from the innermost group outward:

javascriptjavascript
const result = ((2 + 3) * (4 - 1)) / 5;
// Step 1: (2 + 3) = 5
// Step 2: (4 - 1) = 3
// Step 3: 5 * 3 = 15
// Step 4: 15 / 5 = 3
 
console.log(result); // 3

Arithmetic Operator Precedence in Practice

Arithmetic operators follow the same PEMDAS/BODMAS rules you know from mathematics, but JavaScript adds a few extras.

OperationOperatorPrecedenceExampleResult
Exponentiation**142 ** 38
Multiplication*134 * 312
Division/1310 / 25
Remainder%1310 % 31
Addition+125 + 38
Subtraction-129 - 45
javascriptjavascript
// Real-world example: calculating a shopping cart total with tax and discount
const subtotal = 3 * 29.99 + 2 * 14.99;
// Evaluates as: (3 * 29.99) + (2 * 14.99)
// = 89.97 + 29.98 = 119.95
 
const taxRate = 0.08;
const discount = 10;
 
// Parentheses needed here to get the right calculation
const total = (subtotal - discount) * (1 + taxRate);
console.log(total.toFixed(2)); // "118.75"

Logical Operator Precedence

Logical operators have a specific order that catches many developers off guard: ! (NOT) executes first, then && (AND), then || (OR).

javascriptjavascript
// Logical NOT has highest precedence among logical operators
const a = !true || false;
// Evaluates as: (!true) || false = false || false = false
 
// AND before OR
const b = true || false && false;
// Evaluates as: true || (false && false) = true || false = true
 
// Common access control pattern
const isAdmin = false;
const isOwner = true;
const isPublished = false;
 
// Without understanding precedence, this is confusing
const canEdit = isAdmin || isOwner && isPublished;
// Evaluates as: isAdmin || (isOwner && isPublished)
// = false || (true && false) = false || false = false
 
// What the developer probably wanted
const canEditFixed = (isAdmin || isOwner) && isPublished;
// = (false || true) && false = true && false = false
 
// OR maybe this
const canEditAlt = isAdmin || (isOwner && isPublished);
// = false || (true && false) = false
Common Pitfall with Mixed Logical Operators

When mixing && and || in the same expression, always use parentheses to make your intent clear. The precedence rules are well-defined, but your teammates (and your future self reviewing the code at 2 AM during an incident) will thank you for the explicit grouping.

Comparison and Equality Operators

Comparison operators (<, >, <=, >=) have higher precedence than equality operators (==, ===, !=, !==), and both sit above logical operators:

javascriptjavascript
// Comparison (10) before equality (9) before logical AND (5)
const result = 5 > 3 === true && 10 < 20;
// Step 1: 5 > 3 → true (comparison, precedence 10)
// Step 2: 10 < 20 → true (comparison, precedence 10)
// Step 3: true === true → true (equality, precedence 9)
// Step 4: true && true → true (logical AND, precedence 5)
 
console.log(result); // true
javascriptjavascript
// Practical example: form validation
const age = 25;
const hasConsent = true;
const country = "US";
 
const isEligible = age >= 18 && age <= 65 && hasConsent === true;
// All comparisons evaluate first, then && chains them
// (age >= 18) && (age <= 65) && (hasConsent === true)
// true && true && true = true
console.log(isEligible); // true

Assignment Operator Precedence

Assignment operators have one of the lowest precedence levels (2), which means nearly everything else evaluates before the value is assigned to the variable.

javascriptjavascript
// Assignment happens last
let x = 2 + 3 * 4;
// Step 1: 3 * 4 = 12 (multiplication, precedence 13)
// Step 2: 2 + 12 = 14 (addition, precedence 12)
// Step 3: x = 14 (assignment, precedence 2)
 
console.log(x); // 14

Compound Assignment Operators

Compound assignment operators (+=, -=, *=, etc.) also have precedence 2 and right-to-left associativity:

javascriptjavascript
let score = 100;
score += 5 * 2;
// Step 1: 5 * 2 = 10 (multiplication first)
// Step 2: score = score + 10 = 110 (compound assignment)
 
console.log(score); // 110

The Ternary Operator and Precedence

The ternary (conditional) operator sits at precedence 3, just above assignment. This means comparisons and logical operators evaluate before the ternary decides which branch to take:

javascriptjavascript
// Comparison evaluates before ternary
const age = 20;
const category = age >= 18 ? "adult" : "minor";
// Step 1: age >= 18 → true (comparison, precedence 10)
// Step 2: true ? "adult" : "minor" → "adult" (ternary, precedence 3)
 
console.log(category); // "adult"
javascriptjavascript
// Nested ternary with right-to-left associativity
const score = 85;
const grade = score >= 90 ? "A" : score >= 80 ? "B" : score >= 70 ? "C" : "F";
// Evaluates right-to-left:
// score >= 90 ? "A" : (score >= 80 ? "B" : (score >= 70 ? "C" : "F"))
 
console.log(grade); // "B"

The typeof Operator and Unary Precedence

The typeof operator sits at precedence 15 (unary), which is higher than all arithmetic and logical operators:

javascriptjavascript
// typeof evaluates before comparison
const check = typeof 42 === "number";
// Step 1: typeof 42 → "number" (unary, precedence 15)
// Step 2: "number" === "number" → true (equality, precedence 9)
 
console.log(check); // true
javascriptjavascript
// typeof with arithmetic
const result = typeof 2 + 2;
// Step 1: typeof 2 → "number" (precedence 15)
// Step 2: "number" + 2 → "number2" (string concatenation, precedence 12)
 
console.log(result); // "number2"
 
// To check the type of the expression result, use parentheses
const corrected = typeof (2 + 2);
console.log(corrected); // "number"

Best Practices

Writing Clear Expressions

Following these practices will save you from precedence-related bugs and make your code maintainable across teams.

Use parentheses for complex expressions. Even if you know that && binds tighter than ||, adding parentheses costs nothing and eliminates ambiguity. Code that requires a precedence table lookup to understand is code that will eventually contain a bug.

Break complex expressions into named variables. Instead of writing one massive expression with six operators, split it into intermediate variables with descriptive names. This makes the evaluation order explicit and the code self-documenting.

javascriptjavascript
// Hard to read, requires precedence knowledge
const eligible = age >= 18 && income > 50000 || hasGuarantor && creditScore > 700;
 
// Clear, self-documenting
const meetsAgeAndIncome = age >= 18 && income > 50000;
const hasStrongGuarantor = hasGuarantor && creditScore > 700;
const eligible = meetsAgeAndIncome || hasStrongGuarantor;

Never rely on precedence for side effects. If your expression depends on a specific evaluation order for side effects (like function calls or increments), restructure it into separate statements. Side effects combined with precedence create the kind of bugs that pass code review and break in production.

Learn the top 5 levels by heart. You do not need to memorize all 19 levels. Knowing that unary > arithmetic > comparison > logical > assignment covers 95% of real code situations.

Use strict equality (===) over loose equality (==). Both have the same precedence, but strict equality avoids implicit type conversion issues that interact poorly with other operators in complex expressions.

Common Mistakes and How to Avoid Them

Watch Out for These Pitfalls

These mistakes appear frequently in real codebases and can be difficult to catch during code review because the code looks syntactically correct.

Mixing && and || without parentheses. This is the most common precedence bug. Developers write a || b && c expecting left-to-right evaluation, but && always executes before ||. Always parenthesize mixed logical expressions.

Forgetting that + is both addition and concatenation. When mixing numbers and strings, the + operator can behave unexpectedly because string concatenation and numeric addition share the same precedence level:

javascriptjavascript
const result = "Total: " + 10 + 5;
console.log(result); // "Total: 105" (string concatenation, left to right)
 
const corrected = "Total: " + (10 + 5);
console.log(corrected); // "Total: 15"

Assuming assignment returns nothing. Assignment operators return the assigned value, which can create unexpected behavior when used inside conditions:

javascriptjavascript
// Bug: assignment instead of comparison
let x = 0;
if (x = 5) {
  console.log("This always runs because x = 5 returns 5, which is truthy");
}
 
// Fix: use comparison
if (x === 5) {
  console.log("Correct comparison");
}

Chaining comparisons like math notation. In math, 1 < x < 10 checks if x is between 1 and 10. In JavaScript, it does something completely different:

javascriptjavascript
const x = 15;
const result = 1 < x < 10;
// Step 1: 1 < 15 → true (comparison, left to right)
// Step 2: true < 10 → true (true coerces to 1, and 1 < 10 is true)
 
console.log(result); // true (wrong! 15 is not less than 10)
 
// Correct way
const correct = x > 1 && x < 10;
console.log(correct); // false

Using typeof with expressions without parentheses. When you want to check the type of an expression result, always wrap the expression in parentheses because typeof has very high precedence: typeof (a + b) not typeof a + b.

Next Steps

Practice with interactive exercises

Open your browser DevTools console and type out the expressions from this guide. Predict the result before pressing Enter, then verify. Pay special attention to mixed arithmetic and logical expressions.

Review your existing code for precedence issues

Search your codebase for expressions that mix && and || without parentheses. Add explicit grouping wherever the intent is not immediately obvious.

Learn JavaScript conditional statements

Operator precedence directly affects how conditions evaluate. Study how conditional statements use these operators to control program flow.

Explore type checking operators

Operators like typeof and instanceof have specific precedence levels that affect how they combine with other operators in expressions.

Rune AI

Rune AI

Key Insights

  • Precedence levels: JavaScript has 19 levels; higher numbers execute first, with parentheses at the top (19) and comma at the bottom (1)
  • Associativity: determines direction when operators share a level; most are left-to-right, but assignment and exponentiation are right-to-left
  • Parentheses first: always use parentheses in mixed logical expressions (&& with ||) to prevent subtle bugs
  • Readability over cleverness: break complex expressions into named variables instead of relying on precedence knowledge
  • Common trap: && binds tighter than ||, so a || b && c evaluates as a || (b && c), not (a || b) && c
Powered by Rune AI

Frequently Asked Questions

What is operator precedence in JavaScript?

Operator precedence is the set of rules that determines which operator in a compound expression gets evaluated first. JavaScript defines 19 precedence levels, with higher levels executing before lower levels. For example, multiplication (precedence 13) always executes before addition (precedence 12), which is why `2 + 3 * 4` equals 14, not 20.

Do parentheses override operator precedence?

Yes. Parentheses have the highest precedence level (19) in JavaScript, so any expression wrapped in parentheses evaluates before anything else. This is the most reliable way to control evaluation order. When in doubt about how an expression will evaluate, use parentheses to make your intent explicit.

What is associativity in JavaScript operators?

ssociativity determines the evaluation direction when two operators have the same precedence level. Left-to-right associativity means the leftmost operator executes first (e.g., `10 - 5 - 2` becomes `(10 - 5) - 2`). Right-to-left associativity means the rightmost goes first (e.g., `a = b = 5` becomes `a = (b = 5)`). Most operators are left-to-right; assignment, exponentiation, and ternary are right-to-left.

Why does `&&` have higher precedence than `||`?

This design follows Boolean algebra conventions where AND is analogous to multiplication and OR is analogous to addition. Just as `2 + 3 * 4` evaluates multiplication first, `true || false && false` evaluates AND first. This means `a || b && c` always evaluates as `a || (b && c)`, which catches many developers by surprise. Always use parentheses when mixing these operators.

Should I memorize the entire precedence table?

No. Memorizing all 19 levels is unnecessary for practical JavaScript development. Focus on five key relationships: unary operators (`!`, `typeof`) beat arithmetic (`*`, `/`, `+`, `-`), arithmetic beats comparison (`<`, `>`, `===`), comparison beats logical (`&&`, `||`), and logical beats assignment (`=`). For everything else, use parentheses to make the order explicit.

How does operator precedence affect performance?

Operator precedence has no impact on runtime performance. The JavaScript engine resolves precedence during parsing (before execution), so the evaluation order is determined at compile time. Whether you write `2 + 3 * 4` or `2 + (3 * 4)`, the engine executes the same operations in the same order. Parentheses are purely a readability tool with zero performance cost.

Conclusion

JavaScript operator precedence is a foundational concept that determines how every expression in your code gets evaluated. By understanding the core precedence levels and using parentheses strategically, you can write expressions that behave exactly as intended and remain readable to every developer on your team. The most practical approach is to memorize the five key precedence tiers (unary, arithmetic, comparison, logical, assignment) and use explicit grouping for everything else.

Tags

Beginner JavaScriptProgramming FundamentalsJavaScriptOperator PrecedenceWeb DevelopmentJavaScript Operators
Previous
JS Operators: Arithmetic, Logical & Comparison
13 min read · beginner
Next
How to Use the typeof Operator in JavaScript: Full Guide
11 min read · beginner

More in this topic

OffscreenCanvas API in JS for UI Performance

Master the OffscreenCanvas API to offload rendering from the main thread. Covers worker-based 2D and WebGL rendering, animation loops inside workers, bitmap transfer, double buffering, chart rendering pipelines, image processing, and performance measurement strategies.

Advanced Web Workers for High Performance JS

Master Web Workers for truly parallel JavaScript execution. Covers dedicated and shared workers, structured cloning, transferable objects, SharedArrayBuffer with Atomics, worker pools, task scheduling, Comlink RPC patterns, module workers, and performance profiling strategies.

JavaScript Macros and Abstract Code Generation

Master JavaScript code generation techniques for compile-time and runtime metaprogramming. Covers AST manipulation, Babel plugin authorship, tagged template literals as macros, code generation pipelines, source-to-source transformation, compile-time evaluation, and safe eval alternatives.

On this page

    Share
    RuneHub
    Programming Education Platform

    Master programming through interactive tutorials, hands-on projects, and personalized learning paths designed for every skill level.

    Stay Updated

    Learning Tracks

    • Programming Languages
    • Web Development
    • Data Structures & Algorithms
    • Backend Development

    Practice

    • Interview Prep
    • Interactive Quizzes
    • Flashcards
    • Learning Roadmaps

    Resources

    • Tutorials
    • Tech Trends
    • Search
    • RuneAI

    Support

    • FAQ
    • About Us
    • Privacy Policy
    • Terms of Service
    • System Status
    © 2026 RuneAI. All rights reserved.