CINXE.COM

Expressions and operators - JavaScript | MDN

<!doctype html><html lang="en-US" prefix="og: https://ogp.me/ns#"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><link rel="icon" href="https://developer.mozilla.org/favicon-48x48.bc390275e955dacb2e65.png"/><link rel="apple-touch-icon" href="https://developer.mozilla.org/apple-touch-icon.528534bba673c38049c2.png"/><meta name="theme-color" content="#ffffff"/><link rel="manifest" href="https://developer.mozilla.org/manifest.f42880861b394dd4dc9b.json"/><link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="MDN Web Docs"/><title>Expressions and operators - JavaScript | MDN</title><link rel="alternate" title="Ausdrücke und Operatoren" href="https://developer.mozilla.org/de/docs/Web/JavaScript/Guide/Expressions_and_operators" hrefLang="de"/><link rel="alternate" title="Expresiones y operadores" href="https://developer.mozilla.org/es/docs/Web/JavaScript/Guide/Expressions_and_operators" hrefLang="es"/><link rel="alternate" title="Expressions et opérateurs" href="https://developer.mozilla.org/fr/docs/Web/JavaScript/Guide/Expressions_and_operators" hrefLang="fr"/><link rel="alternate" title="式と演算子" href="https://developer.mozilla.org/ja/docs/Web/JavaScript/Guide/Expressions_and_operators" hrefLang="ja"/><link rel="alternate" title="표현식과 연산자" href="https://developer.mozilla.org/ko/docs/Web/JavaScript/Guide/Expressions_and_operators" hrefLang="ko"/><link rel="alternate" title="Expressões e operadores" href="https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Guide/Expressions_and_operators" hrefLang="pt"/><link rel="alternate" title="Выражения и операторы" href="https://developer.mozilla.org/ru/docs/Web/JavaScript/Guide/Expressions_and_operators" hrefLang="ru"/><link rel="alternate" title="表达式与运算符" href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Guide/Expressions_and_operators" hrefLang="zh"/><link rel="alternate" title="運算式與運算子" href="https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Guide/Expressions_and_operators" hrefLang="zh-Hant"/><link rel="alternate" title="Expressions and operators" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_operators" hrefLang="en"/><link rel="preload" as="font" type="font/woff2" href="/static/media/Inter.var.c2fe3cb2b7c746f7966a.woff2" crossorigin=""/><link rel="alternate" type="application/rss+xml" title="MDN Blog RSS Feed" href="https://developer.mozilla.org/en-US/blog/rss.xml" hrefLang="en"/><meta name="description" content="This chapter describes JavaScript&#x27;s expressions and operators, including assignment, comparison, arithmetic, bitwise, logical, string, ternary and more."/><meta property="og:url" content="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_operators"/><meta property="og:title" content="Expressions and operators - JavaScript | MDN"/><meta property="og:type" content="website"/><meta property="og:locale" content="en_US"/><meta property="og:description" content="This chapter describes JavaScript&#x27;s expressions and operators, including assignment, comparison, arithmetic, bitwise, logical, string, ternary and more."/><meta property="og:image" content="https://developer.mozilla.org/mdn-social-share.d893525a4fb5fb1f67a2.png"/><meta property="og:image:type" content="image/png"/><meta property="og:image:height" content="1080"/><meta property="og:image:width" content="1920"/><meta property="og:image:alt" content="The MDN Web Docs logo, featuring a blue accent color, displayed on a solid black background."/><meta property="og:site_name" content="MDN Web Docs"/><meta name="twitter:card" content="summary_large_image"/><meta name="twitter:creator" content="MozDevNet"/><link rel="canonical" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_operators"/><style media="print">.article-actions-container,.document-toc-container,.language-menu,.main-menu-toggle,.on-github,.page-footer,.place,.sidebar,.top-banner,.top-navigation-main,ul.prev-next{display:none!important}.main-page-content,.main-page-content pre{padding:2px}.main-page-content pre{border-left-width:2px}</style><script src="/static/js/gtag.js" defer=""></script><script defer="" src="/static/js/main.f565372a.js"></script><link href="/static/css/main.3d9e7a02.css" rel="stylesheet"/></head><body><script>if(document.body.addEventListener("load",(t=>{t.target.classList.contains("interactive")&&t.target.setAttribute("data-readystate","complete")}),{capture:!0}),window&&document.documentElement){const t={light:"#ffffff",dark:"#1b1b1b"};try{const e=window.localStorage.getItem("theme");e&&(document.documentElement.className=e,document.documentElement.style.backgroundColor=t[e]);const o=window.localStorage.getItem("nop");o&&(document.documentElement.dataset.nop=o)}catch(t){console.warn("Unable to read theme from localStorage",t)}}</script><div id="root"><ul id="nav-access" class="a11y-nav"><li><a id="skip-main" href="#content">Skip to main content</a></li><li><a id="skip-search" href="#top-nav-search-input">Skip to search</a></li><li><a id="skip-select-language" href="#languages-switcher-button">Skip to select language</a></li></ul><div class="page-wrapper category-javascript document-page"><div class="top-banner loading"><section class="place top container"></section></div><div class="sticky-header-container"><header class="top-navigation "><div class="container "><div class="top-navigation-wrap"><a href="/en-US/" class="logo" aria-label="MDN homepage"><svg id="mdn-docs-logo" xmlns="http://www.w3.org/2000/svg" x="0" y="0" viewBox="0 0 694.9 104.4" style="enable-background:new 0 0 694.9 104.4" xml:space="preserve" role="img"><title>MDN Web Docs</title><path d="M40.3 0 11.7 92.1H0L28.5 0h11.8zm10.4 0v92.1H40.3V0h10.4zM91 0 62.5 92.1H50.8L79.3 0H91zm10.4 0v92.1H91V0h10.4z" class="logo-m"></path><path d="M627.9 95.6h67v8.8h-67v-8.8z" class="logo-_"></path><path d="M367 42h-4l-10.7 30.8h-5.5l-10.8-26h-.4l-10.5 26h-5.2L308.7 42h-3.8v-5.6H323V42h-6.5l6.8 20.4h.4l10.3-26h4.7l11.2 26h.5l5.7-20.3h-6.2v-5.6H367V42zm34.9 20c-.4 3.2-2 5.9-4.7 8.2-2.8 2.3-6.5 3.4-11.3 3.4-5.4 0-9.7-1.6-13.1-4.7-3.3-3.2-5-7.7-5-13.7 0-5.7 1.6-10.3 4.7-14s7.4-5.5 12.9-5.5c5.1 0 9.1 1.6 11.9 4.7s4.3 6.9 4.3 11.3c0 1.5-.2 3-.5 4.7h-25.6c.3 7.7 4 11.6 10.9 11.6 2.9 0 5.1-.7 6.5-2 1.5-1.4 2.5-3 3-4.9l6 .9zM394 51.3c.2-2.4-.4-4.7-1.8-6.9s-3.8-3.3-7-3.3c-3.1 0-5.3 1-6.9 3-1.5 2-2.5 4.4-2.8 7.2H394zm51 2.4c0 5-1.3 9.5-4 13.7s-6.9 6.2-12.7 6.2c-6 0-10.3-2.2-12.7-6.7-.1.4-.2 1.4-.4 2.9s-.3 2.5-.4 2.9h-7.3c.3-1.7.6-3.5.8-5.3.3-1.8.4-3.7.4-5.5V22.3h-6v-5.6H416v27c1.1-2.2 2.7-4.1 4.7-5.7 2-1.6 4.8-2.4 8.4-2.4 4.6 0 8.4 1.6 11.4 4.7 3 3.2 4.5 7.6 4.5 13.4zm-7.7.6c0-4.2-1-7.4-3-9.5-2-2.2-4.4-3.3-7.4-3.3-3.4 0-6 1.2-8 3.7-1.9 2.4-2.9 5-3 7.7V57c0 3 1 5.6 3 7.7s4.5 3.1 7.6 3.1c3.6 0 6.3-1.3 8.1-3.9 1.8-2.7 2.7-5.9 2.7-9.6zm69.2 18.5h-13.2v-7.2c-1.2 2.2-2.8 4.1-4.9 5.6-2.1 1.6-4.8 2.4-8.3 2.4-4.8 0-8.7-1.6-11.6-4.9-2.9-3.2-4.3-7.7-4.3-13.3 0-5 1.3-9.6 4-13.7 2.6-4.1 6.9-6.2 12.8-6.2 5.7 0 9.8 2.2 12.3 6.5V22.3h-8.6v-5.6h15.8v50.6h6v5.5zM493.2 56v-4.4c-.1-3-1.2-5.5-3.2-7.3s-4.4-2.8-7.2-2.8c-3.6 0-6.3 1.3-8.2 3.9-1.9 2.6-2.8 5.8-2.8 9.6 0 4.1 1 7.3 3 9.5s4.5 3.3 7.4 3.3c3.2 0 5.8-1.3 7.8-3.8 2.1-2.6 3.1-5.3 3.2-8zm53.1-1.4c0 5.6-1.8 10.2-5.3 13.7s-8.2 5.3-13.9 5.3-10.1-1.7-13.4-5.1c-3.3-3.4-5-7.9-5-13.5 0-5.3 1.6-9.9 4.7-13.7 3.2-3.8 7.9-5.7 14.2-5.7s11 1.9 14.1 5.7c3 3.7 4.6 8.1 4.6 13.3zm-7.7-.2c0-4-1-7.2-3-9.5s-4.8-3.5-8.2-3.5c-3.6 0-6.4 1.2-8.3 3.7s-2.9 5.6-2.9 9.5c0 3.7.9 6.8 2.8 9.4 1.9 2.6 4.6 3.9 8.3 3.9 3.6 0 6.4-1.3 8.4-3.8 1.9-2.6 2.9-5.8 2.9-9.7zm45 5.8c-.4 3.2-1.9 6.3-4.4 9.1-2.5 2.9-6.4 4.3-11.8 4.3-5.2 0-9.4-1.6-12.6-4.8-3.2-3.2-4.8-7.7-4.8-13.7 0-5.5 1.6-10.1 4.7-13.9 3.2-3.8 7.6-5.7 13.2-5.7 2.3 0 4.6.3 6.7.8 2.2.5 4.2 1.5 6.2 2.9l1.5 9.5-5.9.7-1.3-6.1c-2.1-1.2-4.5-1.8-7.2-1.8-3.5 0-6.1 1.2-7.7 3.7-1.7 2.5-2.5 5.7-2.5 9.6 0 4.1.9 7.3 2.7 9.5 1.8 2.3 4.4 3.4 7.8 3.4 5.2 0 8.2-2.9 9.2-8.8l6.2 1.3zm34.7 1.9c0 3.6-1.5 6.5-4.6 8.5s-7 3-11.7 3c-5.7 0-10.6-1.2-14.6-3.6l1.2-8.8 5.7.6-.2 4.7c1.1.5 2.3.9 3.6 1.1s2.6.3 3.9.3c2.4 0 4.5-.4 6.5-1.3 1.9-.9 2.9-2.2 2.9-4.1 0-1.8-.8-3.1-2.3-3.8s-3.5-1.3-5.8-1.7-4.6-.9-6.9-1.4c-2.3-.6-4.2-1.6-5.7-2.9-1.6-1.4-2.3-3.5-2.3-6.3 0-4.1 1.5-6.9 4.6-8.5s6.4-2.4 9.9-2.4c2.6 0 5 .3 7.2.9 2.2.6 4.3 1.4 6.1 2.4l.8 8.8-5.8.7-.8-5.7c-2.3-1-4.7-1.6-7.2-1.6-2.1 0-3.7.4-5.1 1.1-1.3.8-2 2-2 3.8 0 1.7.8 2.9 2.3 3.6 1.5.7 3.4 1.2 5.7 1.6 2.2.4 4.5.8 6.7 1.4 2.2.6 4.1 1.6 5.7 3 1.4 1.6 2.2 3.7 2.2 6.6zM197.6 73.2h-17.1v-5.5h3.8V51.9c0-3.7-.7-6.3-2.1-7.9-1.4-1.6-3.3-2.3-5.7-2.3-3.2 0-5.6 1.1-7.2 3.4s-2.4 4.6-2.5 6.9v15.6h6v5.5h-17.1v-5.5h3.8V51.9c0-3.8-.7-6.4-2.1-7.9-1.4-1.5-3.3-2.3-5.6-2.3-3.2 0-5.5 1.1-7.2 3.3-1.6 2.2-2.4 4.5-2.5 6.9v15.8h6.9v5.5h-20.2v-5.5h6V42.4h-6.1v-5.6h13.4v6.4c1.2-2.1 2.7-3.8 4.7-5.2 2-1.3 4.4-2 7.3-2s5.3.7 7.5 2.1c2.2 1.4 3.7 3.5 4.5 6.4 1.1-2.5 2.7-4.5 4.9-6.1s4.8-2.4 7.9-2.4c3.5 0 6.5 1.1 8.9 3.3s3.7 5.6 3.7 10.2v18.2h6.1v5.5zm42.5 0h-13.2V66c-1.2 2.2-2.8 4.1-4.9 5.6-2.1 1.6-4.8 2.4-8.3 2.4-4.8 0-8.7-1.6-11.6-4.9-2.9-3.2-4.3-7.7-4.3-13.3 0-5 1.3-9.6 4-13.7 2.6-4.1 6.9-6.2 12.8-6.2s9.8 2.2 12.3 6.5V22.7h-8.6v-5.6h15.8v50.6h6v5.5zm-13.3-16.8V52c-.1-3-1.2-5.5-3.2-7.3s-4.4-2.8-7.2-2.8c-3.6 0-6.3 1.3-8.2 3.9-1.9 2.6-2.8 5.8-2.8 9.6 0 4.1 1 7.3 3 9.5s4.5 3.3 7.4 3.3c3.2 0 5.8-1.3 7.8-3.8 2.1-2.6 3.1-5.3 3.2-8zm61.5 16.8H269v-5.5h6V51.9c0-3.7-.7-6.3-2.2-7.9-1.4-1.6-3.4-2.3-5.7-2.3-3.1 0-5.6 1-7.4 3s-2.8 4.4-2.9 7v15.9h6v5.5h-19.3v-5.5h6V42.4h-6.2v-5.6h13.6V43c2.6-4.6 6.8-6.9 12.7-6.9 3.6 0 6.7 1.1 9.2 3.3s3.7 5.6 3.7 10.2v18.2h6v5.4h-.2z" class="logo-text"></path></svg></a><button title="Open main menu" type="button" class="button action has-icon main-menu-toggle" aria-haspopup="menu" aria-label="Open main menu" aria-expanded="false"><span class="button-wrap"><span class="icon icon-menu "></span><span class="visually-hidden">Open main menu</span></span></button></div><div class="top-navigation-main"><nav class="main-nav" aria-label="Main menu"><ul class="main-menu nojs"><li class="top-level-entry-container active"><button type="button" id="references-button" class="top-level-entry menu-toggle" aria-controls="references-menu" aria-expanded="false">References</button><a href="/en-US/docs/Web" class="top-level-entry">References</a><ul id="references-menu" class="submenu references hidden inline-submenu-lg" aria-labelledby="references-button"><li class="apis-link-container mobile-only "><a href="/en-US/docs/Web" class="submenu-item "><div class="submenu-icon"></div><div class="submenu-content-container"><div class="submenu-item-heading">Overview / Web Technology</div><p class="submenu-item-description">Web technology reference for developers</p></div></a></li><li class="html-link-container "><a href="/en-US/docs/Web/HTML" class="submenu-item "><div class="submenu-icon html"></div><div class="submenu-content-container"><div class="submenu-item-heading">HTML</div><p class="submenu-item-description">Structure of content on the web</p></div></a></li><li class="css-link-container "><a href="/en-US/docs/Web/CSS" class="submenu-item "><div class="submenu-icon css"></div><div class="submenu-content-container"><div class="submenu-item-heading">CSS</div><p class="submenu-item-description">Code used to describe document style</p></div></a></li><li class="javascript-link-container "><a href="/en-US/docs/Web/JavaScript" class="submenu-item "><div class="submenu-icon javascript"></div><div class="submenu-content-container"><div class="submenu-item-heading">JavaScript</div><p class="submenu-item-description">General-purpose scripting language</p></div></a></li><li class="http-link-container "><a href="/en-US/docs/Web/HTTP" class="submenu-item "><div class="submenu-icon http"></div><div class="submenu-content-container"><div class="submenu-item-heading">HTTP</div><p class="submenu-item-description">Protocol for transmitting web resources</p></div></a></li><li class="apis-link-container "><a href="/en-US/docs/Web/API" class="submenu-item "><div class="submenu-icon apis"></div><div class="submenu-content-container"><div class="submenu-item-heading">Web APIs</div><p class="submenu-item-description">Interfaces for building web applications</p></div></a></li><li class="apis-link-container "><a href="/en-US/docs/Mozilla/Add-ons/WebExtensions" class="submenu-item "><div class="submenu-icon"></div><div class="submenu-content-container"><div class="submenu-item-heading">Web Extensions</div><p class="submenu-item-description">Developing extensions for web browsers</p></div></a></li><li class=" "><a href="/en-US/docs/Web/Accessibility" class="submenu-item "><div class="submenu-icon"></div><div class="submenu-content-container"><div class="submenu-item-heading">Accessibility</div><p class="submenu-item-description">Build web projects usable for all</p></div></a></li><li class="apis-link-container desktop-only "><a href="/en-US/docs/Web" class="submenu-item "><div class="submenu-icon"></div><div class="submenu-content-container"><div class="submenu-item-heading">Web Technology</div><p class="submenu-item-description">Web technology reference for developers</p></div></a></li></ul></li><li class="top-level-entry-container "><button type="button" id="learn-button" class="top-level-entry menu-toggle" aria-controls="learn-menu" aria-expanded="false">Learn</button><a href="/en-US/docs/Learn_web_development" class="top-level-entry">Learn</a><ul id="learn-menu" class="submenu learn hidden inline-submenu-lg" aria-labelledby="learn-button"><li class="apis-link-container mobile-only "><a href="/en-US/docs/Learn_web_development" class="submenu-item "><div class="submenu-icon learn"></div><div class="submenu-content-container"><div class="submenu-item-heading">Overview / MDN Learning Area</div><p class="submenu-item-description">Learn web development</p></div></a></li><li class="apis-link-container desktop-only "><a href="/en-US/docs/Learn_web_development" class="submenu-item "><div class="submenu-icon learn"></div><div class="submenu-content-container"><div class="submenu-item-heading">MDN Learning Area</div><p class="submenu-item-description">Learn web development</p></div></a></li><li class="html-link-container "><a href="/en-US/docs/Learn_web_development/Core/Structuring_content" class="submenu-item "><div class="submenu-icon html"></div><div class="submenu-content-container"><div class="submenu-item-heading">HTML</div><p class="submenu-item-description">Learn to structure web content with HTML</p></div></a></li><li class="css-link-container "><a href="/en-US/docs/Learn_web_development/Core/Styling_basics" class="submenu-item "><div class="submenu-icon css"></div><div class="submenu-content-container"><div class="submenu-item-heading">CSS</div><p class="submenu-item-description">Learn to style content using CSS</p></div></a></li><li class="javascript-link-container "><a href="/en-US/docs/Learn_web_development/Core/Scripting" class="submenu-item "><div class="submenu-icon javascript"></div><div class="submenu-content-container"><div class="submenu-item-heading">JavaScript</div><p class="submenu-item-description">Learn to run scripts in the browser</p></div></a></li><li class=" "><a href="/en-US/docs/Learn_web_development/Core/Accessibility" class="submenu-item "><div class="submenu-icon"></div><div class="submenu-content-container"><div class="submenu-item-heading">Accessibility</div><p class="submenu-item-description">Learn to make the web accessible to all</p></div></a></li></ul></li><li class="top-level-entry-container "><button type="button" id="mdn-plus-button" class="top-level-entry menu-toggle" aria-controls="mdn-plus-menu" aria-expanded="false">Plus</button><a href="/en-US/plus" class="top-level-entry">Plus</a><ul id="mdn-plus-menu" class="submenu mdn-plus hidden inline-submenu-lg" aria-labelledby="mdn-plus-button"><li class=" "><a href="/en-US/plus" class="submenu-item "><div class="submenu-icon"></div><div class="submenu-content-container"><div class="submenu-item-heading">Overview</div><p class="submenu-item-description">A customized MDN experience</p></div></a></li><li class=" "><a href="/en-US/plus/ai-help" class="submenu-item "><div class="submenu-icon"></div><div class="submenu-content-container"><div class="submenu-item-heading">AI Help</div><p class="submenu-item-description">Get real-time assistance and support</p></div></a></li><li class=" "><a href="/en-US/plus/updates" class="submenu-item "><div class="submenu-icon"></div><div class="submenu-content-container"><div class="submenu-item-heading">Updates</div><p class="submenu-item-description">All browser compatibility updates at a glance</p></div></a></li><li class=" "><a href="/en-US/plus/docs/features/overview" class="submenu-item "><div class="submenu-icon"></div><div class="submenu-content-container"><div class="submenu-item-heading">Documentation</div><p class="submenu-item-description">Learn how to use MDN Plus</p></div></a></li><li class=" "><a href="/en-US/plus/docs/faq" class="submenu-item "><div class="submenu-icon"></div><div class="submenu-content-container"><div class="submenu-item-heading">FAQ</div><p class="submenu-item-description">Frequently asked questions about MDN Plus</p></div></a></li></ul></li><li class="top-level-entry-container "><a class="top-level-entry menu-link" href="/en-US/curriculum/">Curriculum <sup class="new">New</sup></a></li><li class="top-level-entry-container "><a class="top-level-entry menu-link" href="/en-US/blog/">Blog</a></li><li class="top-level-entry-container "><button type="button" id="tools-button" class="top-level-entry menu-toggle" aria-controls="tools-menu" aria-expanded="false">Tools</button><ul id="tools-menu" class="submenu tools hidden inline-submenu-lg" aria-labelledby="tools-button"><li class=" "><a href="/en-US/play" class="submenu-item "><div class="submenu-icon"></div><div class="submenu-content-container"><div class="submenu-item-heading">Playground</div><p class="submenu-item-description">Write, test and share your code</p></div></a></li><li class=" "><a href="/en-US/observatory" class="submenu-item "><div class="submenu-icon"></div><div class="submenu-content-container"><div class="submenu-item-heading">HTTP Observatory</div><p class="submenu-item-description">Scan a website for free</p></div></a></li><li class=" "><a href="/en-US/plus/ai-help" class="submenu-item "><div class="submenu-icon"></div><div class="submenu-content-container"><div class="submenu-item-heading">AI Help</div><p class="submenu-item-description">Get real-time assistance and support</p></div></a></li></ul></li></ul></nav><div class="header-search"><form action="/en-US/search" class="search-form search-widget" id="top-nav-search-form" role="search"><label id="top-nav-search-label" for="top-nav-search-input" class="visually-hidden">Search MDN</label><input aria-activedescendant="" aria-autocomplete="list" aria-controls="top-nav-search-menu" aria-expanded="false" aria-labelledby="top-nav-search-label" autoComplete="off" id="top-nav-search-input" role="combobox" type="search" class="search-input-field" name="q" placeholder="   " required="" value=""/><button type="button" class="button action has-icon clear-search-button"><span class="button-wrap"><span class="icon icon-cancel "></span><span class="visually-hidden">Clear search input</span></span></button><button type="submit" class="button action has-icon search-button"><span class="button-wrap"><span class="icon icon-search "></span><span class="visually-hidden">Search</span></span></button><div id="top-nav-search-menu" role="listbox" aria-labelledby="top-nav-search-label"></div></form></div><div class="theme-switcher-menu"><button type="button" class="button action has-icon theme-switcher-menu small" aria-haspopup="menu"><span class="button-wrap"><span class="icon icon-theme-os-default "></span>Theme</span></button></div><ul class="auth-container"><li><a href="/users/fxa/login/authenticate/?next=%2Fen-US%2Fdocs%2FWeb%2FJavaScript%2FGuide%2FExpressions_and_operators" class="login-link" rel="nofollow">Log in</a></li><li><a href="/users/fxa/login/authenticate/?next=%2Fen-US%2Fdocs%2FWeb%2FJavaScript%2FGuide%2FExpressions_and_operators" target="_self" rel="nofollow" class="button primary mdn-plus-subscribe-link"><span class="button-wrap">Sign up for free</span></a></li></ul></div></div></header><div class="article-actions-container"><div class="container"><button type="button" class="button action has-icon sidebar-button" aria-label="Expand sidebar" aria-expanded="false" aria-controls="sidebar-quicklinks"><span class="button-wrap"><span class="icon icon-sidebar "></span></span></button><nav class="breadcrumbs-container" aria-label="Breadcrumb"><ol typeof="BreadcrumbList" vocab="https://schema.org/" aria-label="breadcrumbs"><li property="itemListElement" typeof="ListItem"><a href="/en-US/docs/Web" class="breadcrumb" property="item" typeof="WebPage"><span property="name">References</span></a><meta property="position" content="1"/></li><li property="itemListElement" typeof="ListItem"><a href="/en-US/docs/Web/JavaScript" class="breadcrumb" property="item" typeof="WebPage"><span property="name">JavaScript</span></a><meta property="position" content="2"/></li><li property="itemListElement" typeof="ListItem"><a href="/en-US/docs/Web/JavaScript/Guide" class="breadcrumb" property="item" typeof="WebPage"><span property="name">Guide</span></a><meta property="position" content="3"/></li><li property="itemListElement" typeof="ListItem"><a href="/en-US/docs/Web/JavaScript/Guide/Expressions_and_operators" class="breadcrumb-current-page" property="item" typeof="WebPage"><span property="name">Expressions and operators</span></a><meta property="position" content="4"/></li></ol></nav><div class="article-actions"><button type="button" class="button action has-icon article-actions-toggle" aria-label="Article actions"><span class="button-wrap"><span class="icon icon-ellipses "></span><span class="article-actions-dialog-heading">Article Actions</span></span></button><ul class="article-actions-entries"><li class="article-actions-entry"><div class="languages-switcher-menu open-on-focus-within"><button id="languages-switcher-button" type="button" class="button action small has-icon languages-switcher-menu" aria-haspopup="menu"><span class="button-wrap"><span class="icon icon-language "></span>English (US)</span></button><div class="hidden"><ul class="submenu language-menu " aria-labelledby="language-menu-button"><li class=" "><form class="submenu-item locale-redirect-setting"><div class="group"><label class="switch"><input type="checkbox" name="locale-redirect"/><span class="slider"></span><span class="label">Remember language</span></label><a href="https://github.com/orgs/mdn/discussions/739" rel="external noopener noreferrer" target="_blank" title="Enable this setting to automatically switch to this language when it&#x27;s available. (Click to learn more.)"><span class="icon icon-question-mark "></span></a></div></form></li><li class=" "><a data-locale="de" href="/de/docs/Web/JavaScript/Guide/Expressions_and_operators" class="button submenu-item"><span>Deutsch</span><span title="Diese Übersetzung ist Teil eines Experiments."><span class="icon icon-experimental "></span></span></a></li><li class=" "><a data-locale="es" href="/es/docs/Web/JavaScript/Guide/Expressions_and_operators" class="button submenu-item"><span>Español</span></a></li><li class=" "><a data-locale="fr" href="/fr/docs/Web/JavaScript/Guide/Expressions_and_operators" class="button submenu-item"><span>Français</span></a></li><li class=" "><a data-locale="ja" href="/ja/docs/Web/JavaScript/Guide/Expressions_and_operators" class="button submenu-item"><span>日本語</span></a></li><li class=" "><a data-locale="ko" href="/ko/docs/Web/JavaScript/Guide/Expressions_and_operators" class="button submenu-item"><span>한국어</span></a></li><li class=" "><a data-locale="pt-BR" href="/pt-BR/docs/Web/JavaScript/Guide/Expressions_and_operators" class="button submenu-item"><span>Português (do Brasil)</span></a></li><li class=" "><a data-locale="ru" href="/ru/docs/Web/JavaScript/Guide/Expressions_and_operators" class="button submenu-item"><span>Русский</span></a></li><li class=" "><a data-locale="zh-CN" href="/zh-CN/docs/Web/JavaScript/Guide/Expressions_and_operators" class="button submenu-item"><span>中文 (简体)</span></a></li><li class=" "><a data-locale="zh-TW" href="/zh-TW/docs/Web/JavaScript/Guide/Expressions_and_operators" class="button submenu-item"><span>正體中文 (繁體)</span></a></li></ul></div></div></li></ul></div></div></div></div><div class="main-wrapper"><div class="sidebar-container"><aside id="sidebar-quicklinks" class="sidebar"><button type="button" class="button action backdrop" aria-label="Collapse sidebar"><span class="button-wrap"></span></button><nav aria-label="Related Topics" class="sidebar-inner"><header class="sidebar-actions"><section class="sidebar-filter-container"><div class="sidebar-filter "><label id="sidebar-filter-label" class="sidebar-filter-label" for="sidebar-filter-input"><span class="icon icon-filter"></span><span class="visually-hidden">Filter sidebar</span></label><input id="sidebar-filter-input" autoComplete="off" class="sidebar-filter-input-field false" type="text" placeholder="Filter" value=""/><button type="button" class="button action has-icon clear-sidebar-filter-button"><span class="button-wrap"><span class="icon icon-cancel "></span><span class="visually-hidden">Clear filter input</span></span></button></div></section></header><div class="sidebar-inner-nav"><div class="in-nav-toc"><div class="document-toc-container"><section class="document-toc"><header><h2 class="document-toc-heading">In this article</h2></header><ul class="document-toc-list"><li class="document-toc-item "><a class="document-toc-link" href="#assignment_operators">Assignment operators</a></li><li class="document-toc-item "><a class="document-toc-link" href="#comparison_operators">Comparison operators</a></li><li class="document-toc-item "><a class="document-toc-link" href="#arithmetic_operators">Arithmetic operators</a></li><li class="document-toc-item "><a class="document-toc-link" href="#bitwise_operators">Bitwise operators</a></li><li class="document-toc-item "><a class="document-toc-link" href="#logical_operators">Logical operators</a></li><li class="document-toc-item "><a class="document-toc-link" href="#bigint_operators">BigInt operators</a></li><li class="document-toc-item "><a class="document-toc-link" href="#string_operators">String operators</a></li><li class="document-toc-item "><a class="document-toc-link" href="#conditional_ternary_operator">Conditional (ternary) operator</a></li><li class="document-toc-item "><a class="document-toc-link" href="#comma_operator">Comma operator</a></li><li class="document-toc-item "><a class="document-toc-link" href="#unary_operators">Unary operators</a></li><li class="document-toc-item "><a class="document-toc-link" href="#relational_operators">Relational operators</a></li><li class="document-toc-item "><a class="document-toc-link" href="#basic_expressions">Basic expressions</a></li></ul></section></div></div><div class="sidebar-body"><ol><li class="section"><a href="/en-US/docs/Web/JavaScript">JavaScript</a></li><li class="section">Tutorials and guides</li><li class="toggle"><details><summary>Beginner's tutorials</summary><ol><li><a href="/en-US/docs/Learn_web_development/Getting_started/Your_first_website/Adding_interactivity">Your first website: Adding interactivity</a></li><li><a href="/en-US/docs/Learn_web_development/Core/Scripting">Dynamic scripting with JavaScript</a></li><li><a href="/en-US/docs/Learn_web_development/Core/Frameworks_libraries">JavaScript frameworks and libraries</a></li></ol></details></li><li class="toggle"><details open=""><summary>JavaScript Guide</summary><ol><li><a href="/en-US/docs/Web/JavaScript/Guide/Introduction">Introduction</a></li><li><a href="/en-US/docs/Web/JavaScript/Guide/Grammar_and_types">Grammar and types</a></li><li><a href="/en-US/docs/Web/JavaScript/Guide/Control_flow_and_error_handling">Control flow and error handling</a></li><li><a href="/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration">Loops and iteration</a></li><li><a href="/en-US/docs/Web/JavaScript/Guide/Functions">Functions</a></li><li><em><a href="/en-US/docs/Web/JavaScript/Guide/Expressions_and_operators" aria-current="page">Expressions and operators</a></em></li><li><a href="/en-US/docs/Web/JavaScript/Guide/Numbers_and_strings">Numbers and strings</a></li><li><a href="/en-US/docs/Web/JavaScript/Guide/Representing_dates_times">Representing dates &amp; times</a></li><li><a href="/en-US/docs/Web/JavaScript/Guide/Regular_expressions">Regular expressions</a></li><li><a href="/en-US/docs/Web/JavaScript/Guide/Indexed_collections">Indexed collections</a></li><li><a href="/en-US/docs/Web/JavaScript/Guide/Keyed_collections">Keyed collections</a></li><li><a href="/en-US/docs/Web/JavaScript/Guide/Working_with_objects">Working with objects</a></li><li><a href="/en-US/docs/Web/JavaScript/Guide/Using_classes">Using classes</a></li><li><a href="/en-US/docs/Web/JavaScript/Guide/Using_promises">Using promises</a></li><li><a href="/en-US/docs/Web/JavaScript/Guide/Typed_arrays">JavaScript typed arrays</a></li><li><a href="/en-US/docs/Web/JavaScript/Guide/Iterators_and_generators">Iterators and generators</a></li><li><a href="/en-US/docs/Web/JavaScript/Guide/Internationalization">Internationalization</a></li><li><a href="/en-US/docs/Web/JavaScript/Guide/Meta_programming">Meta programming</a></li><li><a href="/en-US/docs/Web/JavaScript/Guide/Modules">JavaScript modules</a></li></ol></details></li><li class="toggle"><details><summary>Intermediate</summary><ol><li><a href="/en-US/docs/Learn_web_development/Extensions/Advanced_JavaScript_objects">Advanced JavaScript objects</a></li><li><a href="/en-US/docs/Learn_web_development/Extensions/Async_JS">Asynchronous JavaScript</a></li><li><a href="/en-US/docs/Learn_web_development/Extensions/Client-side_APIs">Client-side web APIs</a></li><li><a href="/en-US/docs/Web/JavaScript/Language_overview">Language overview</a></li><li><a href="/en-US/docs/Web/JavaScript/Data_structures">JavaScript data structures</a></li><li><a href="/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness">Equality comparisons and sameness</a></li><li><a href="/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties">Enumerability and ownership of properties</a></li><li><a href="/en-US/docs/Web/JavaScript/Closures">Closures</a></li></ol></details></li><li class="toggle"><details><summary>Advanced</summary><ol><li><a href="/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain">Inheritance and the prototype chain</a></li><li><a href="/en-US/docs/Web/JavaScript/Memory_management">Memory Management</a></li><li><a href="/en-US/docs/Web/JavaScript/Event_loop">Concurrency model and Event Loop</a></li></ol></details></li><li class="section"><a href="/en-US/docs/Web/JavaScript/Reference">References</a></li><li class="toggle"><details><summary>Built-in objects</summary><ol><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects">Overview</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError">AggregateError</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer">ArrayBuffer</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncFunction">AsyncFunction</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator">AsyncGenerator</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGeneratorFunction">AsyncGeneratorFunction</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncIterator">AsyncIterator</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics">Atomics</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt">BigInt</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array">BigInt64Array</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array">BigUint64Array</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView">DataView</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date">Date</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURI">decodeURI()</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent">decodeURIComponent()</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI">encodeURI()</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent">encodeURIComponent()</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error">Error</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape">escape()</a><abbr class="icon icon-deprecated" title="Deprecated. Not for use in new websites."> <span class="visually-hidden">Deprecated</span> </abbr></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval">eval()</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError">EvalError</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry">FinalizationRegistry</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array">Float16Array</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array">Float32Array</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array">Float64Array</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function">Function</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator">Generator</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/GeneratorFunction">GeneratorFunction</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis">globalThis</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Infinity">Infinity</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array">Int16Array</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array">Int32Array</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array">Int8Array</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/InternalError">InternalError</a><abbr class="icon icon-nonstandard" title="Non-standard. Check cross-browser support before using."> <span class="visually-hidden">Non-standard</span> </abbr></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl">Intl</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite">isFinite()</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN">isNaN()</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator">Iterator</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON">JSON</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map">Map</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math">Math</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN">NaN</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">Number</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat">parseFloat()</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt">parseInt()</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy">Proxy</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError">RangeError</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError">ReferenceError</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect">Reflect</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp">RegExp</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set">Set</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer">SharedArrayBuffer</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol">Symbol</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError">SyntaxError</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal">Temporal</a><abbr class="icon icon-experimental" title="Experimental. Expect behavior to change in the future."> <span class="visually-hidden">Experimental</span> </abbr></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray">TypedArray</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError">TypeError</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array">Uint16Array</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array">Uint32Array</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array">Uint8Array</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray">Uint8ClampedArray</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined">undefined</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/unescape">unescape()</a><abbr class="icon icon-deprecated" title="Deprecated. Not for use in new websites."> <span class="visually-hidden">Deprecated</span> </abbr></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError">URIError</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap">WeakMap</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef">WeakRef</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet">WeakSet</a></li></ol></details></li><li class="toggle"><details><summary>Expressions &amp; operators</summary><ol><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators">Overview</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Addition">Addition (+)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Addition_assignment">Addition assignment (+=)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Assignment">Assignment (=)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/async_function">async function expression</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/async_function*">async function* expression</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/await">await</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_AND">Bitwise AND (&amp;)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_AND_assignment">Bitwise AND assignment (&amp;=)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_NOT">Bitwise NOT (~)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_OR">Bitwise OR (|)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_OR_assignment">Bitwise OR assignment (|=)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_XOR">Bitwise XOR (^)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_XOR_assignment">Bitwise XOR assignment (^=)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/class">class expression</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Comma_operator">Comma operator (,)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_operator">Conditional (ternary) operator</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Decrement">Decrement (--)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/delete">delete</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment">Destructuring assignment</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Division">Division (/)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Division_assignment">Division assignment (/=)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Equality">Equality (==)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation">Exponentiation (**)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation_assignment">Exponentiation assignment (**=)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/function">function expression</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/function*">function* expression</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Greater_than">Greater than (&gt;)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Greater_than_or_equal">Greater than or equal (&gt;=)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Grouping">Grouping operator ( )</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/import.meta">import.meta</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/import">import()</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/in">in</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Increment">Increment (++)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Inequality">Inequality (!=)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/instanceof">instanceof</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Left_shift">Left shift (&lt;&lt;)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Left_shift_assignment">Left shift assignment (&lt;&lt;=)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Less_than">Less than (&lt;)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Less_than_or_equal">Less than or equal (&lt;=)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Logical_AND">Logical AND (&amp;&amp;)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Logical_AND_assignment">Logical AND assignment (&amp;&amp;=)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Logical_NOT">Logical NOT (!)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR">Logical OR (||)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR_assignment">Logical OR assignment (||=)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Multiplication">Multiplication (*)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Multiplication_assignment">Multiplication assignment (*=)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/new">new</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/new.target">new.target</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/null">null</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_assignment">Nullish coalescing assignment (??=)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing">Nullish coalescing operator (??)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer">Object initializer</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Operator_precedence">Operator precedence</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining">Optional chaining (?.)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors">Property accessors</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Remainder">Remainder (%)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Remainder_assignment">Remainder assignment (%=)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Right_shift">Right shift (&gt;&gt;)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Right_shift_assignment">Right shift assignment (&gt;&gt;=)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax">Spread syntax (...)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality">Strict equality (===)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Strict_inequality">Strict inequality (!==)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Subtraction">Subtraction (-)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Subtraction_assignment">Subtraction assignment (-=)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/super">super</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/this">this</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/typeof">typeof</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Unary_negation">Unary negation (-)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Unary_plus">Unary plus (+)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Unsigned_right_shift">Unsigned right shift (&gt;&gt;&gt;)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Unsigned_right_shift_assignment">Unsigned right shift assignment (&gt;&gt;&gt;=)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/void">void operator</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/yield">yield</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/yield*">yield*</a></li></ol></details></li><li class="toggle"><details><summary>Statements &amp; declarations</summary><ol><li><a href="/en-US/docs/Web/JavaScript/Reference/Statements">Overview</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/async_function">async function</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/async_function*">async function*</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/block">Block statement</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/break">break</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/class">class</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/const">const</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/continue">continue</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/debugger">debugger</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/do...while">do...while</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/Empty">Empty statement</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/export">export</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/Expression_statement">Expression statement</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/for">for</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of">for await...of</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/for...in">for...in</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/for...of">for...of</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/function">function</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/function*">function*</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/if...else">if...else</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/import">import</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/label">Labeled statement</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/let">let</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/return">return</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/switch">switch</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/throw">throw</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/try...catch">try...catch</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/var">var</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/while">while</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/with">with</a><abbr class="icon icon-deprecated" title="Deprecated. Not for use in new websites."> <span class="visually-hidden">Deprecated</span> </abbr></li></ol></details></li><li class="toggle"><details><summary>Functions</summary><ol><li><a href="/en-US/docs/Web/JavaScript/Reference/Functions">Overview</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions">Arrow function expressions</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters">Default parameters</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Functions/get">get</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Functions/Method_definitions">Method definitions</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters">Rest parameters</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Functions/set">set</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Functions/arguments">The arguments object</a></li></ol></details></li><li class="toggle"><details><summary>Classes</summary><ol><li><a href="/en-US/docs/Web/JavaScript/Reference/Classes">Overview</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Classes/constructor">constructor</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Classes/extends">extends</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Classes/Private_properties">Private properties</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Classes/Public_class_fields">Public class fields</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Classes/static">static</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Classes/Static_initialization_blocks">Static initialization blocks</a></li></ol></details></li><li class="toggle"><details><summary>Regular expressions</summary><ol><li><a href="/en-US/docs/Web/JavaScript/Reference/Regular_expressions">Overview</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Backreference">Backreference: \1, \2</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Capturing_group">Capturing group: (...)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Character_class_escape">Character class escape: \d, \D, \w, \W, \s, \S</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Character_class">Character class: [...], [^...]</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Character_escape">Character escape: \n, \u{...}</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Disjunction">Disjunction: |</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Input_boundary_assertion">Input boundary assertion: ^, $</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Literal_character">Literal character: a, b</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Lookahead_assertion">Lookahead assertion: (?=...), (?!...)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Lookbehind_assertion">Lookbehind assertion: (?&lt;=...), (?&lt;!...)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Modifier">Modifier: (?ims-ims:...)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Named_backreference">Named backreference: \k&lt;name&gt;</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Named_capturing_group">Named capturing group: (?&lt;name&gt;...)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Non-capturing_group">Non-capturing group: (?:...)</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Quantifier">Quantifier: *, +, ?, {n}, {n,}, {n,m}</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Unicode_character_class_escape">Unicode character class escape: \p{...}, \P{...}</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Wildcard">Wildcard: .</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Word_boundary_assertion">Word boundary assertion: \b, \B</a></li></ol></details></li><li class="toggle"><details><summary>Errors</summary><ol><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors">Overview</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Promise_any_all_rejected">AggregateError: No Promise in Promise.any was resolved</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Property_access_denied">Error: Permission denied to access property "x"</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Too_much_recursion">InternalError: too much recursion</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Not_a_valid_code_point">RangeError: argument is not a valid code point</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/BigInt_division_by_zero">RangeError: BigInt division by zero</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/BigInt_negative_exponent">RangeError: BigInt negative exponent</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Form_must_be_one_of">RangeError: form must be one of 'NFC', 'NFD', 'NFKC', or 'NFKD'</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_array_length">RangeError: invalid array length</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_date">RangeError: invalid date</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Precision_range">RangeError: precision is out of range</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Bad_radix">RangeError: radix must be an integer</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Resulting_string_too_large">RangeError: repeat count must be less than infinity</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Negative_repetition_count">RangeError: repeat count must be non-negative</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Cant_be_converted_to_BigInt_because_it_isnt_an_integer">RangeError: x can't be converted to BigInt because it isn't an integer</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Not_defined">ReferenceError: "x" is not defined</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Undeclared_var">ReferenceError: assignment to undeclared variable "x"</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Cant_access_lexical_declaration_before_init">ReferenceError: can't access lexical declaration 'X' before initialization</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Deprecated_caller_or_arguments_usage">ReferenceError: deprecated caller or arguments usage</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Super_not_called">ReferenceError: must call super constructor before using 'this' in derived class constructor</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Super_called_twice">ReferenceError: super() called twice in derived class constructor</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Bad_strict_arguments_eval">SyntaxError: 'arguments'/'eval' can't be defined or assigned to in strict mode code</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Deprecated_octal_literal">SyntaxError: "0"-prefixed octal literals are deprecated</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Strict_non_simple_params">SyntaxError: "use strict" not allowed in function with non-simple parameters</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Reserved_identifier">SyntaxError: "x" is a reserved identifier</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Regex_backslash_at_end_of_pattern">SyntaxError: \ at end of pattern</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_for-of_initializer">SyntaxError: a declaration in the head of a for-of loop can't have an initializer</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Delete_in_strict_mode">SyntaxError: applying the 'delete' operator to an unqualified name is deprecated</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Arguments_not_allowed">SyntaxError: arguments is not valid in fields</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Bad_await">SyntaxError: await is only valid in async functions, async generators and modules</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/await_yield_in_parameter">SyntaxError: await/yield expression can't be used in parameter</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Cant_use_nullish_coalescing_unparenthesized">SyntaxError: cannot use `??` unparenthesized within `||` and `&amp;&amp;` expressions</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Regex_character_class_escape_in_class_range">SyntaxError: character class escape cannot be used in class range in regular expression</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Bad_continue">SyntaxError: continue must be inside loop</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Regex_duplicate_capture_group_name">SyntaxError: duplicate capture group name in regular expression</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Duplicate_parameter">SyntaxError: duplicate formal argument x</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_for-in_initializer">SyntaxError: for-in loop head declarations may not have initializers</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Unnamed_function_statement">SyntaxError: function statement requires a name</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Function_label">SyntaxError: functions cannot be labelled</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Either_be_both_static_or_non-static">SyntaxError: getter and setter for private name #x should either be both static or non-static</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Getter_no_arguments">SyntaxError: getter functions must have no arguments</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Identifier_after_number">SyntaxError: identifier starts immediately after numeric literal</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Illegal_character">SyntaxError: illegal character</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/import_decl_module_top_level">SyntaxError: import declarations may only appear at top level of a module</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Regex_incomplete_quantifier">SyntaxError: incomplete quantifier in regular expression</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_assignment_left-hand_side">SyntaxError: invalid assignment left-hand side</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_BigInt_syntax">SyntaxError: invalid BigInt syntax</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Regex_invalid_capture_group_name">SyntaxError: invalid capture group name in regular expression</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Regex_invalid_char_in_class">SyntaxError: invalid character in class in regular expression</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Regex_invalid_class_set_operation">SyntaxError: invalid class set operation in regular expression</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Regex_invalid_decimal_escape">SyntaxError: invalid decimal escape in regular expression</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Regex_invalid_identity_escape">SyntaxError: invalid identity escape in regular expression</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Regex_invalid_named_capture_reference">SyntaxError: invalid named capture reference in regular expression</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Regex_invalid_property_name">SyntaxError: invalid property name in regular expression</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Regex_invalid_range_in_character_class">SyntaxError: invalid range in character class</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Regex_invalid_group">SyntaxError: invalid regexp group</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Bad_regexp_flag">SyntaxError: invalid regular expression flag "x"</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Regex_invalid_unicode_escape">SyntaxError: invalid unicode escape in regular expression</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/JSON_bad_parse">SyntaxError: JSON.parse: bad parsing</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Label_not_found">SyntaxError: label not found</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Missing_colon_after_property_id">SyntaxError: missing : after property id</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Missing_parenthesis_after_argument_list">SyntaxError: missing ) after argument list</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Missing_parenthesis_after_condition">SyntaxError: missing ) after condition</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Missing_bracket_after_list">SyntaxError: missing ] after element list</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Missing_curly_after_function_body">SyntaxError: missing } after function body</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Missing_curly_after_property_list">SyntaxError: missing } after property list</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Missing_initializer_in_const">SyntaxError: missing = in const declaration</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Missing_formal_parameter">SyntaxError: missing formal parameter</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Missing_name_after_dot_operator">SyntaxError: missing name after . operator</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/No_variable_name">SyntaxError: missing variable name</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Regex_negated_char_class_with_strings">SyntaxError: negated character class with strings in regular expression</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Bad_new_optional">SyntaxError: new keyword cannot be used with an optional chain</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Regex_nothing_to_repeat">SyntaxError: nothing to repeat</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Regex_numbers_out_of_order_in_quantifier">SyntaxError: numbers out of order in {} quantifier.</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Deprecated_octal_escape_sequence">SyntaxError: octal escape sequences can't be used in untagged template literals or in strict mode code</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Parameter_after_rest_parameter">SyntaxError: parameter after rest parameter</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Cant_delete_private_fields">SyntaxError: private fields can't be deleted</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Duplicate_proto">SyntaxError: property name __proto__ appears more than once in object literal</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Regex_raw_bracket">SyntaxError: raw bracket is not allowed in regular expression with unicode flag</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Redeclared_parameter">SyntaxError: redeclaration of formal parameter "x"</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Undeclared_private_field_or_method">SyntaxError: reference to undeclared private field or method #x</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Rest_with_default">SyntaxError: rest parameter may not have a default</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Bad_return">SyntaxError: return not in function</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Setter_one_argument">SyntaxError: setter functions must have one argument</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/String_literal_EOL">SyntaxError: string literal contains an unescaped line break</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Bad_super_call">SyntaxError: super() is only valid in derived class constructors</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Bad_optional_template">SyntaxError: tagged template cannot be used with optional chain</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Hash_outside_class">SyntaxError: Unexpected '#' used outside of class body</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Unexpected_token">SyntaxError: Unexpected token</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Bad_break">SyntaxError: unlabeled break must be inside loop or switch</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Unparenthesized_unary_expr_lhs_exponentiation">SyntaxError: unparenthesized unary expression can't appear on the left-hand side of '**'</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Bad_super_prop">SyntaxError: use of super property/member accesses only valid within methods or eval code within methods</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Deprecated_source_map_pragma">SyntaxError: Using //@ to indicate sourceURL pragmas is deprecated. Use //# instead</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/is_not_iterable">TypeError: 'x' is not iterable</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Unexpected_type">TypeError: "x" is (not) "y"</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Not_a_constructor">TypeError: "x" is not a constructor</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Not_a_function">TypeError: "x" is not a function</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/No_non-null_object">TypeError: "x" is not a non-null object</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Read-only">TypeError: "x" is read-only</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/BigInt_not_serializable">TypeError: BigInt value can't be serialized in JSON</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Builtin_ctor_no_new">TypeError: calling a builtin X constructor without new is forbidden</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Get_set_missing_private">TypeError: can't access/set private field or method: object is not the right class</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Cant_assign_to_property">TypeError: can't assign to property "x" on "y": not an object</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Cant_convert_BigInt_to_number">TypeError: can't convert BigInt to number</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Cant_convert_x_to_BigInt">TypeError: can't convert x to BigInt</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Cant_define_property_object_not_extensible">TypeError: can't define property "x": "obj" is not extensible</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Non_configurable_array_element">TypeError: can't delete non-configurable array element</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Cant_redefine_property">TypeError: can't redefine non-configurable property "x"</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Cant_set_prototype">TypeError: can't set prototype of this object</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_prototype">TypeError: can't set prototype: it would cause a prototype chain cycle</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/in_operator_no_object">TypeError: cannot use 'in' operator to search for 'x' in 'y'</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Class_ctor_no_new">TypeError: class constructors must be invoked with 'new'</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value">TypeError: cyclic object value</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_derived_return">TypeError: derived class constructor returned invalid value x</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Private_setter_only">TypeError: getting private setter-only property</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Private_double_initialization">TypeError: Initializing an object twice is an error with private fields/methods</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/invalid_right_hand_side_instanceof_operand">TypeError: invalid 'instanceof' operand 'x'</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Array_sort_argument">TypeError: invalid Array.prototype.sort argument</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_const_assignment">TypeError: invalid assignment to const "x"</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Constructor_cant_be_used_directly">TypeError: Iterator/AsyncIterator constructor can't be used directly</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Requires_global_RegExp">TypeError: matchAll/replaceAll must be called with a global RegExp</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/More_arguments_needed">TypeError: More arguments needed</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/No_properties">TypeError: null/undefined has no properties</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Cant_delete">TypeError: property "x" is non-configurable and can't be deleted</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Reduce_of_empty_array_with_no_initial_value">TypeError: Reduce of empty array with no initial value</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Getter_only">TypeError: setting getter-only property "x"</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Key_not_weakly_held">TypeError: WeakSet key/WeakMap value 'x' must be an object or an unregistered symbol</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Called_on_incompatible_type">TypeError: X.prototype.y called on incompatible type</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Malformed_URI">URIError: malformed URI sequence</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Already_has_pragma">Warning: -file- is being assigned a //# sourceMappingURL, but already has one</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Errors/Stmt_after_return">Warning: unreachable code after return statement</a></li></ol></details></li><li class="toggle"><details><summary>Misc</summary><ol><li><a href="/en-US/docs/Web/JavaScript/JavaScript_technologies_overview">JavaScript technologies overview</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Lexical_grammar">Lexical grammar</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Iteration_protocols">Iteration protocols</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Strict_mode">Strict mode</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Template_literals">Template literals</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Trailing_commas">Trailing commas</a></li><li><a href="/en-US/docs/Web/JavaScript/Reference/Deprecated_and_obsolete_features">Deprecated features</a></li></ol></details></li></ol></div></div><section class="place side"></section></nav></aside><div class="toc-container"><aside class="toc"><nav><div class="document-toc-container"><section class="document-toc"><header><h2 class="document-toc-heading">In this article</h2></header><ul class="document-toc-list"><li class="document-toc-item "><a class="document-toc-link" href="#assignment_operators">Assignment operators</a></li><li class="document-toc-item "><a class="document-toc-link" href="#comparison_operators">Comparison operators</a></li><li class="document-toc-item "><a class="document-toc-link" href="#arithmetic_operators">Arithmetic operators</a></li><li class="document-toc-item "><a class="document-toc-link" href="#bitwise_operators">Bitwise operators</a></li><li class="document-toc-item "><a class="document-toc-link" href="#logical_operators">Logical operators</a></li><li class="document-toc-item "><a class="document-toc-link" href="#bigint_operators">BigInt operators</a></li><li class="document-toc-item "><a class="document-toc-link" href="#string_operators">String operators</a></li><li class="document-toc-item "><a class="document-toc-link" href="#conditional_ternary_operator">Conditional (ternary) operator</a></li><li class="document-toc-item "><a class="document-toc-link" href="#comma_operator">Comma operator</a></li><li class="document-toc-item "><a class="document-toc-link" href="#unary_operators">Unary operators</a></li><li class="document-toc-item "><a class="document-toc-link" href="#relational_operators">Relational operators</a></li><li class="document-toc-item "><a class="document-toc-link" href="#basic_expressions">Basic expressions</a></li></ul></section></div></nav></aside><section class="place side"></section></div></div><main id="content" class="main-content "><article class="main-page-content" lang="en-US"><header><h1>Expressions and operators</h1></header><div class="section-content"><ul class="prev-next"><li><a class="button secondary" href="/en-US/docs/Web/JavaScript/Guide/Functions"><span class="button-wrap"> Previous </span></a></li><li><a class="button secondary" href="/en-US/docs/Web/JavaScript/Guide/Numbers_and_strings"><span class="button-wrap"> Next </span></a></li></ul> <p>This chapter describes JavaScript's expressions and operators, including assignment, comparison, arithmetic, bitwise, logical, string, ternary and more.</p> <p>At a high level, an <em>expression</em> is a valid unit of code that resolves to a value. There are two types of expressions: those that have side effects (such as assigning values) and those that purely <em>evaluate</em>.</p> <p>The expression <code>x = 7</code> is an example of the first type. This expression uses the <code>=</code> <em>operator</em> to assign the value seven to the variable <code>x</code>. The expression itself evaluates to <code>7</code>.</p> <p>The expression <code>3 + 4</code> is an example of the second type. This expression uses the <code>+</code> operator to add <code>3</code> and <code>4</code> together and produces a value, <code>7</code>. However, if it's not eventually part of a bigger construct (for example, a <a href="/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#declarations">variable declaration</a> like <code>const z = 3 + 4</code>), its result will be immediately discarded — this is usually a programmer mistake because the evaluation doesn't produce any effects.</p> <p>As the examples above also illustrate, all complex expressions are joined by <em>operators</em>, such as <code>=</code> and <code>+</code>. In this section, we will introduce the following operators:</p> <ul> <li><a href="#assignment_operators">Assignment operators</a></li> <li><a href="#comparison_operators">Comparison operators</a></li> <li><a href="#arithmetic_operators">Arithmetic operators</a></li> <li><a href="#bitwise_operators">Bitwise operators</a></li> <li><a href="#logical_operators">Logical operators</a></li> <li><a href="#bigint_operators">BigInt operators</a></li> <li><a href="#string_operators">String operators</a></li> <li><a href="#conditional_ternary_operator">Conditional (ternary) operator</a></li> <li><a href="#comma_operator">Comma operator</a></li> <li><a href="#unary_operators">Unary operators</a></li> <li><a href="#relational_operators">Relational operators</a></li> </ul> <p>These operators join operands either formed by higher-precedence operators or one of the <a href="#basic_expressions">basic expressions</a>. A complete and detailed list of operators and expressions is also available in the <a href="/en-US/docs/Web/JavaScript/Reference/Operators">reference</a>.</p> <p>The <em>precedence</em> of operators determines the order they are applied when evaluating an expression. For example:</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>const x = 1 + 2 * 3; const y = 2 * 3 + 1; </code></pre></div> <p>Despite <code>*</code> and <code>+</code> coming in different orders, both expressions would result in <code>7</code> because <code>*</code> has precedence over <code>+</code>, so the <code>*</code>-joined expression will always be evaluated first. You can override operator precedence by using parentheses (which creates a <a href="#grouping_operator">grouped expression</a> — the basic expression). To see a complete table of operator precedence as well as various caveats, see the <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Operator_precedence#table">Operator Precedence Reference</a> page.</p> <p>JavaScript has both <em>binary</em> and <em>unary</em> operators, and one special ternary operator, the conditional operator. A binary operator requires two operands, one before the operator and one after the operator:</p> <pre class="brush: plain notranslate">operand1 operator operand2 </pre> <p>For example, <code>3 + 4</code> or <code>x * y</code>. This form is called an <em>infix</em> binary operator, because the operator is placed between two operands. All binary operators in JavaScript are infix.</p> <p>A unary operator requires a single operand, either before or after the operator:</p> <pre class="brush: plain notranslate">operator operand operand operator </pre> <p>For example, <code>x++</code> or <code>++x</code>. The <code>operator operand</code> form is called a <em>prefix</em> unary operator, and the <code>operand operator</code> form is called a <em>postfix</em> unary operator. <code>++</code> and <code>--</code> are the only postfix operators in JavaScript — all other operators, like <code>!</code>, <code>typeof</code>, etc. are prefix.</p></div><section aria-labelledby="assignment_operators"><h2 id="assignment_operators"><a href="#assignment_operators">Assignment operators</a></h2><div class="section-content"><p>An assignment operator assigns a value to its left operand based on the value of its right operand. The simple assignment operator is equal (<code>=</code>), which assigns the value of its right operand to its left operand. That is, <code>x = f()</code> is an assignment expression that assigns the value of <code>f()</code> to <code>x</code>.</p> <p>There are also compound assignment operators that are shorthand for the operations listed in the following table:</p> <figure class="table-container"><table> <thead> <tr> <th>Name</th> <th>Shorthand operator</th> <th>Meaning</th> </tr> </thead> <tbody> <tr> <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Assignment">Assignment</a></td> <td><code>x = f()</code></td> <td><code>x = f()</code></td> </tr> <tr> <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Addition_assignment">Addition assignment</a></td> <td><code>x += f()</code></td> <td><code>x = x + f()</code></td> </tr> <tr> <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Subtraction_assignment">Subtraction assignment</a></td> <td><code>x -= f()</code></td> <td><code>x = x - f()</code></td> </tr> <tr> <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Multiplication_assignment">Multiplication assignment</a></td> <td><code>x *= f()</code></td> <td><code>x = x * f()</code></td> </tr> <tr> <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Division_assignment">Division assignment</a></td> <td><code>x /= f()</code></td> <td><code>x = x / f()</code></td> </tr> <tr> <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Remainder_assignment">Remainder assignment</a></td> <td><code>x %= f()</code></td> <td><code>x = x % f()</code></td> </tr> <tr> <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation_assignment">Exponentiation assignment</a></td> <td><code>x **= f()</code></td> <td><code>x = x ** f()</code></td> </tr> <tr> <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Left_shift_assignment">Left shift assignment</a></td> <td><code>x &lt;&lt;= f()</code></td> <td><code>x = x &lt;&lt; f()</code></td> </tr> <tr> <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Right_shift_assignment">Right shift assignment</a></td> <td><code>x &gt;&gt;= f()</code></td> <td><code>x = x &gt;&gt; f()</code></td> </tr> <tr> <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Unsigned_right_shift_assignment">Unsigned right shift assignment</a></td> <td><code>x &gt;&gt;&gt;= f()</code></td> <td><code>x = x &gt;&gt;&gt; f()</code></td> </tr> <tr> <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_AND_assignment">Bitwise AND assignment</a></td> <td><code>x &amp;= f()</code></td> <td><code>x = x &amp; f()</code></td> </tr> <tr> <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_XOR_assignment">Bitwise XOR assignment</a></td> <td><code>x ^= f()</code></td> <td><code>x = x ^ f()</code></td> </tr> <tr> <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_OR_assignment">Bitwise OR assignment</a></td> <td><code>x |= f()</code></td> <td><code>x = x | f()</code></td> </tr> <tr> <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Logical_AND_assignment">Logical AND assignment</a></td> <td><code>x &amp;&amp;= f()</code></td> <td><code>x &amp;&amp; (x = f())</code></td> </tr> <tr> <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR_assignment">Logical OR assignment</a></td> <td><code>x ||= f()</code></td> <td><code>x || (x = f())</code></td> </tr> <tr> <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_assignment">Nullish coalescing assignment</a></td> <td><code>x ??= f()</code></td> <td><code>x ?? (x = f())</code></td> </tr> </tbody> </table></figure></div></section><section aria-labelledby="assigning_to_properties"><h3 id="assigning_to_properties"><a href="#assigning_to_properties">Assigning to properties</a></h3><div class="section-content"><p>If an expression evaluates to an <a href="/en-US/docs/Web/JavaScript/Guide/Working_with_objects">object</a>, then the left-hand side of an assignment expression may make assignments to properties of that expression. For example:</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>const obj = {}; obj.x = 3; console.log(obj.x); // Prints 3. console.log(obj); // Prints { x: 3 }. const key = "y"; obj[key] = 5; console.log(obj[key]); // Prints 5. console.log(obj); // Prints { x: 3, y: 5 }. </code></pre></div> <p>For more information about objects, read <a href="/en-US/docs/Web/JavaScript/Guide/Working_with_objects">Working with Objects</a>.</p> <p>If an expression does not evaluate to an object, then assignments to properties of that expression do not assign:</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>const val = 0; val.x = 3; console.log(val.x); // Prints undefined. console.log(val); // Prints 0. </code></pre></div> <p>In <a href="/en-US/docs/Web/JavaScript/Reference/Strict_mode#converting_mistakes_into_errors">strict mode</a>, the code above throws, because one cannot assign properties to primitives.</p> <p>It is an error to assign values to unmodifiable properties or to properties of an expression without properties (<code>null</code> or <code>undefined</code>).</p></div></section><section aria-labelledby="destructuring"><h3 id="destructuring"><a href="#destructuring">Destructuring</a></h3><div class="section-content"><p>For more complex assignments, the <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment">destructuring assignment</a> syntax is a JavaScript expression that makes it possible to extract data from arrays or objects using a syntax that mirrors the construction of array and object literals.</p> <p>Without destructuring, it takes multiple statements to extract values from arrays and objects:</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>const foo = ["one", "two", "three"]; const one = foo[0]; const two = foo[1]; const three = foo[2]; </code></pre></div> <p>With destructuring, you can extract multiple values into distinct variables using a single statement:</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>const [one, two, three] = foo; </code></pre></div></div></section><section aria-labelledby="evaluation_and_nesting"><h3 id="evaluation_and_nesting"><a href="#evaluation_and_nesting">Evaluation and nesting</a></h3><div class="section-content"><p>In general, assignments are used within a variable declaration (i.e., with <a href="/en-US/docs/Web/JavaScript/Reference/Statements/const"><code>const</code></a>, <a href="/en-US/docs/Web/JavaScript/Reference/Statements/let"><code>let</code></a>, or <a href="/en-US/docs/Web/JavaScript/Reference/Statements/var"><code>var</code></a>) or as standalone statements.</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>// Declares a variable x and initializes it to the result of f(). // The result of the x = f() assignment expression is discarded. let x = f(); x = g(); // Reassigns the variable x to the result of g(). </code></pre></div> <p>However, like other expressions, assignment expressions like <code>x = f()</code> evaluate into a result value. Although this result value is usually not used, it can then be used by another expression.</p> <p>Chaining assignments or nesting assignments in other expressions can result in surprising behavior. For this reason, some JavaScript style guides <a href="https://github.com/airbnb/javascript/blob/master/README.md#variables--no-chain-assignment" class="external" target="_blank">discourage chaining or nesting assignments</a>. Nevertheless, assignment chaining and nesting may occur sometimes, so it is important to be able to understand how they work.</p> <p>By chaining or nesting an assignment expression, its result can itself be assigned to another variable. It can be logged, it can be put inside an array literal or function call, and so on.</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>let x; const y = (x = f()); // Or equivalently: const y = x = f(); console.log(y); // Logs the return value of the assignment x = f(). console.log(x = f()); // Logs the return value directly. // An assignment expression can be nested in any place // where expressions are generally allowed, // such as array literals' elements or as function calls' arguments. console.log([0, x = f(), 0]); console.log(f(0, x = f(), 0)); </code></pre></div> <p>The evaluation result matches the expression to the right of the <code>=</code> sign in the "Meaning" column of the table above. That means that <code>x = f()</code> evaluates into whatever <code>f()</code>'s result is, <code>x += f()</code> evaluates into the resulting sum <code>x + f()</code>, <code>x **= f()</code> evaluates into the resulting power <code>x ** f()</code>, and so on.</p> <p>In the case of logical assignments, <code>x &amp;&amp;= f()</code>, <code>x ||= f()</code>, and <code>x ??= f()</code>, the return value is that of the logical operation without the assignment, so <code>x &amp;&amp; f()</code>, <code>x || f()</code>, and <code>x ?? f()</code>, respectively.</p> <p>When chaining these expressions without parentheses or other grouping operators like array literals, the assignment expressions are <strong>grouped right to left</strong> (they are <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Operator_precedence#precedence_and_associativity">right-associative</a>), but they are <strong>evaluated left to right</strong>.</p> <p>Note that, for all assignment operators other than <code>=</code> itself, the resulting values are always based on the operands' values <em>before</em> the operation.</p> <p>For example, assume that the following functions <code>f</code> and <code>g</code> and the variables <code>x</code> and <code>y</code> have been declared:</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>function f() { console.log("F!"); return 2; } function g() { console.log("G!"); return 3; } let x, y; </code></pre></div> <p>Consider these three examples:</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>y = x = f(); y = [f(), x = g()]; x[f()] = g(); </code></pre></div> <h4 id="evaluation_example_1">Evaluation example 1</h4> <p><code>y = x = f()</code> is equivalent to <code>y = (x = f())</code>, because the assignment operator <code>=</code> is <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Operator_precedence#precedence_and_associativity">right-associative</a>. However, it evaluates from left to right:</p> <ol> <li>The assignment expression <code>y = x = f()</code> starts to evaluate. <ol> <li>The <code>y</code> on this assignment's left-hand side evaluates into a reference to the variable named <code>y</code>.</li> <li>The assignment expression <code>x = f()</code> starts to evaluate. <ol> <li>The <code>x</code> on this assignment's left-hand side evaluates into a reference to the variable named <code>x</code>.</li> <li>The function call <code>f()</code> prints "F!" to the console and then evaluates to the number <code>2</code>.</li> <li>That <code>2</code> result from <code>f()</code> is assigned to <code>x</code>.</li> </ol> </li> <li>The assignment expression <code>x = f()</code> has now finished evaluating; its result is the new value of <code>x</code>, which is <code>2</code>.</li> <li>That <code>2</code> result in turn is also assigned to <code>y</code>.</li> </ol> </li> <li>The assignment expression <code>y = x = f()</code> has now finished evaluating; its result is the new value of <code>y</code> – which happens to be <code>2</code>. <code>x</code> and <code>y</code> are assigned to <code>2</code>, and the console has printed "F!".</li> </ol> <h4 id="evaluation_example_2">Evaluation example 2</h4> <p><code>y = [ f(), x = g() ]</code> also evaluates from left to right:</p> <ol> <li>The assignment expression <code>y = [ f(), x = g() ]</code> starts to evaluate. <ol> <li>The <code>y</code> on this assignment's left-hand evaluates into a reference to the variable named <code>y</code>.</li> <li>The inner array literal <code>[ f(), x = g() ]</code> starts to evaluate. <ol> <li>The function call <code>f()</code> prints "F!" to the console and then evaluates to the number <code>2</code>.</li> <li>The assignment expression <code>x = g()</code> starts to evaluate. <ol> <li>The <code>x</code> on this assignment's left-hand side evaluates into a reference to the variable named <code>x</code>.</li> <li>The function call <code>g()</code> prints "G!" to the console and then evaluates to the number <code>3</code>.</li> <li>That <code>3</code> result from <code>g()</code> is assigned to <code>x</code>.</li> </ol> </li> <li>The assignment expression <code>x = g()</code> has now finished evaluating; its result is the new value of <code>x</code>, which is <code>3</code>. That <code>3</code> result becomes the next element in the inner array literal (after the <code>2</code> from the <code>f()</code>).</li> </ol> </li> <li>The inner array literal <code>[ f(), x = g() ]</code> has now finished evaluating; its result is an array with two values: <code>[ 2, 3 ]</code>.</li> <li>That <code>[ 2, 3 ]</code> array is now assigned to <code>y</code>.</li> </ol> </li> <li>The assignment expression <code>y = [ f(), x = g() ]</code> has now finished evaluating; its result is the new value of <code>y</code> – which happens to be <code>[ 2, 3 ]</code>. <code>x</code> is now assigned to <code>3</code>, <code>y</code> is now assigned to <code>[ 2, 3 ]</code>, and the console has printed "F!" then "G!".</li> </ol> <h4 id="evaluation_example_3">Evaluation example 3</h4> <p><code>x[f()] = g()</code> also evaluates from left to right. (This example assumes that <code>x</code> is already assigned to some object. For more information about objects, read <a href="/en-US/docs/Web/JavaScript/Guide/Working_with_objects">Working with Objects</a>.)</p> <ol> <li>The assignment expression <code>x[f()] = g()</code> starts to evaluate. <ol> <li>The <code>x[f()]</code> property access on this assignment's left-hand starts to evaluate. <ol> <li>The <code>x</code> in this property access evaluates into a reference to the variable named <code>x</code>.</li> <li>Then the function call <code>f()</code> prints "F!" to the console and then evaluates to the number <code>2</code>.</li> </ol> </li> <li>The <code>x[f()]</code> property access on this assignment has now finished evaluating; its result is a variable property reference: <code>x[2]</code>.</li> <li>Then the function call <code>g()</code> prints "G!" to the console and then evaluates to the number <code>3</code>.</li> <li>That <code>3</code> is now assigned to <code>x[2]</code>. (This step will succeed only if <code>x</code> is assigned to an <a href="/en-US/docs/Web/JavaScript/Guide/Working_with_objects">object</a>.)</li> </ol> </li> <li>The assignment expression <code>x[f()] = g()</code> has now finished evaluating; its result is the new value of <code>x[2]</code> – which happens to be <code>3</code>. <code>x[2]</code> is now assigned to <code>3</code>, and the console has printed "F!" then "G!".</li> </ol></div></section><section aria-labelledby="avoid_assignment_chains"><h3 id="avoid_assignment_chains"><a href="#avoid_assignment_chains">Avoid assignment chains</a></h3><div class="section-content"><p>Chaining assignments or nesting assignments in other expressions can result in surprising behavior. For this reason, <a href="https://github.com/airbnb/javascript/blob/master/README.md#variables--no-chain-assignment" class="external" target="_blank">chaining assignments in the same statement is discouraged</a>.</p> <p>In particular, putting a variable chain in a <a href="/en-US/docs/Web/JavaScript/Reference/Statements/const"><code>const</code></a>, <a href="/en-US/docs/Web/JavaScript/Reference/Statements/let"><code>let</code></a>, or <a href="/en-US/docs/Web/JavaScript/Reference/Statements/var"><code>var</code></a> statement often does <em>not</em> work. Only the outermost/leftmost variable would get declared; other variables within the assignment chain are <em>not</em> declared by the <code>const</code>/<code>let</code>/<code>var</code> statement. For example:</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>const z = y = x = f(); </code></pre></div> <p>This statement seemingly declares the variables <code>x</code>, <code>y</code>, and <code>z</code>. However, it only actually declares the variable <code>z</code>. <code>y</code> and <code>x</code> are either invalid references to nonexistent variables (in <a href="/en-US/docs/Web/JavaScript/Reference/Strict_mode">strict mode</a>) or, worse, would implicitly create <a href="/en-US/docs/Glossary/Global_variable">global variables</a> for <code>x</code> and <code>y</code> in <a href="/en-US/docs/Glossary/Sloppy_mode">sloppy mode</a>.</p></div></section><section aria-labelledby="comparison_operators"><h2 id="comparison_operators"><a href="#comparison_operators">Comparison operators</a></h2><div class="section-content"><p>A comparison operator compares its operands and returns a logical value based on whether the comparison is true. The operands can be numerical, string, logical, or <a href="/en-US/docs/Web/JavaScript/Guide/Working_with_objects">object</a> values. Strings are compared based on standard lexicographical ordering, using Unicode values. In most cases, if the two operands are not of the same type, JavaScript attempts to convert them to an appropriate type for the comparison. This behavior generally results in comparing the operands numerically. The sole exceptions to type conversion within comparisons involve the <code>===</code> and <code>!==</code> operators, which perform strict equality and inequality comparisons. These operators do not attempt to convert the operands to compatible types before checking equality. The following table describes the comparison operators in terms of this sample code:</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>const var1 = 3; const var2 = 4; </code></pre></div> <figure class="table-container"><table class="standard-table"> <caption> Comparison operators </caption> <thead> <tr> <th scope="col">Operator</th> <th scope="col">Description</th> <th scope="col">Examples returning true</th> </tr> </thead> <tbody> <tr> <td> <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Equality">Equal</a> (<code>==</code>) </td> <td>Returns <code>true</code> if the operands are equal.</td> <td> <code>3 == var1</code> <p><code>"3" == var1</code></p> <code>3 == '3'</code> </td> </tr> <tr> <td> <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Inequality">Not equal</a> (<code>!=</code>) </td> <td>Returns <code>true</code> if the operands are not equal.</td> <td> <code>var1 != 4<br>var2 != "3"</code> </td> </tr> <tr> <td> <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality">Strict equal</a> (<code>===</code>) </td> <td> Returns <code>true</code> if the operands are equal and of the same type. See also <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is"><code>Object.is</code></a> and <a href="/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness">sameness in JS</a>. </td> <td><code>3 === var1</code></td> </tr> <tr> <td> <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Strict_inequality">Strict not equal</a> (<code>!==</code>) </td> <td> Returns <code>true</code> if the operands are of the same type but not equal, or are of different type. </td> <td> <code>var1 !== "3"<br>3 !== '3'</code> </td> </tr> <tr> <td> <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Greater_than">Greater than</a> (<code>&gt;</code>) </td> <td> Returns <code>true</code> if the left operand is greater than the right operand. </td> <td> <code>var2 &gt; var1<br>"12" &gt; 2</code> </td> </tr> <tr> <td> <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Greater_than_or_equal">Greater than or equal</a> (<code>&gt;=</code>) </td> <td> Returns <code>true</code> if the left operand is greater than or equal to the right operand. </td> <td> <code>var2 &gt;= var1<br>var1 &gt;= 3</code> </td> </tr> <tr> <td> <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Less_than">Less than</a> (<code>&lt;</code>) </td> <td> Returns <code>true</code> if the left operand is less than the right operand. </td> <td> <code>var1 &lt; var2<br>"2" &lt; 12</code> </td> </tr> <tr> <td> <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Less_than_or_equal">Less than or equal</a> (<code>&lt;=</code>) </td> <td> Returns <code>true</code> if the left operand is less than or equal to the right operand. </td> <td> <code>var1 &lt;= var2<br>var2 &lt;= 5</code> </td> </tr> </tbody> </table></figure> <div class="notecard note"> <p><strong>Note:</strong> <code>=&gt;</code> is not a comparison operator but rather is the notation for <a href="/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions">Arrow functions</a>.</p> </div></div></section><section aria-labelledby="arithmetic_operators"><h2 id="arithmetic_operators"><a href="#arithmetic_operators">Arithmetic operators</a></h2><div class="section-content"><p>An arithmetic operator takes numerical values (either literals or variables) as their operands and returns a single numerical value. The standard arithmetic operators are addition (<code>+</code>), subtraction (<code>-</code>), multiplication (<code>*</code>), and division (<code>/</code>). These operators work as they do in most other programming languages when used with floating point numbers (in particular, note that division by zero produces <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Infinity"><code>Infinity</code></a>). For example:</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>1 / 2; // 0.5 1 / 2 === 1.0 / 2.0; // this is true </code></pre></div> <p>In addition to the standard arithmetic operations (<code>+</code>, <code>-</code>, <code>*</code>, <code>/</code>), JavaScript provides the arithmetic operators listed in the following table:</p> <figure class="table-container"><table class="fullwidth-table"> <caption> Arithmetic operators </caption> <thead> <tr> <th scope="col">Operator</th> <th scope="col">Description</th> <th scope="col">Example</th> </tr> </thead> <tbody> <tr> <td> <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Remainder">Remainder</a> (<code>%</code>) </td> <td> Binary operator. Returns the integer remainder of dividing the two operands. </td> <td>12 % 5 returns 2.</td> </tr> <tr> <td> <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Increment">Increment</a> (<code>++</code>) </td> <td> Unary operator. Adds one to its operand. If used as a prefix operator (<code>++x</code>), returns the value of its operand after adding one; if used as a postfix operator (<code>x++</code>), returns the value of its operand before adding one. </td> <td> If <code>x</code> is 3, then <code>++x</code> sets <code>x</code> to 4 and returns 4, whereas <code>x++</code> returns 3 and, only then, sets <code>x</code> to 4. </td> </tr> <tr> <td> <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Decrement">Decrement</a> (<code>--</code>) </td> <td> Unary operator. Subtracts one from its operand. The return value is analogous to that for the increment operator. </td> <td> If <code>x</code> is 3, then <code>--x</code> sets <code>x</code> to 2 and returns 2, whereas <code>x--</code> returns 3 and, only then, sets <code>x</code> to 2. </td> </tr> <tr> <td> <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Unary_negation">Unary negation</a> (<code>-</code>) </td> <td>Unary operator. Returns the negation of its operand.</td> <td>If <code>x</code> is 3, then <code>-x</code> returns -3.</td> </tr> <tr> <td> <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Unary_plus">Unary plus</a> (<code>+</code>) </td> <td> Unary operator. Attempts to <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number#number_coercion">convert the operand to a number</a>, if it is not already. </td> <td> <p><code>+"3"</code> returns <code>3</code>.</p> <p><code>+true</code> returns <code>1</code>.</p> </td> </tr> <tr> <td> <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation">Exponentiation operator</a> (<code>**</code>) </td> <td> Calculates the <code>base</code> to the <code>exponent</code> power, that is, <code>base^exponent</code> </td> <td> <code>2 ** 3</code> returns <code>8</code>.<br><code>10 ** -1</code> returns <code>0.1</code>. </td> </tr> </tbody> </table></figure></div></section><section aria-labelledby="bitwise_operators"><h2 id="bitwise_operators"><a href="#bitwise_operators">Bitwise operators</a></h2><div class="section-content"><p>A bitwise operator treats their operands as a set of 32 bits (zeros and ones), rather than as decimal, hexadecimal, or octal numbers. For example, the decimal number nine has a binary representation of 1001. Bitwise operators perform their operations on such binary representations, but they return standard JavaScript numerical values.</p> <p>The following table summarizes JavaScript's bitwise operators.</p> <figure class="table-container"><table> <thead> <tr> <th>Operator</th> <th>Usage</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_AND">Bitwise AND</a></td> <td><code>a &amp; b</code></td> <td>Returns a one in each bit position for which the corresponding bits of both operands are ones.</td> </tr> <tr> <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_OR">Bitwise OR</a></td> <td><code>a | b</code></td> <td>Returns a zero in each bit position for which the corresponding bits of both operands are zeros.</td> </tr> <tr> <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_XOR">Bitwise XOR</a></td> <td><code>a ^ b</code></td> <td>Returns a zero in each bit position for which the corresponding bits are the same. [Returns a one in each bit position for which the corresponding bits are different.]</td> </tr> <tr> <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_NOT">Bitwise NOT</a></td> <td><code>~ a</code></td> <td>Inverts the bits of its operand.</td> </tr> <tr> <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Left_shift">Left shift</a></td> <td><code>a &lt;&lt; b</code></td> <td>Shifts <code>a</code> in binary representation <code>b</code> bits to the left, shifting in zeros from the right.</td> </tr> <tr> <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Right_shift">Sign-propagating right shift</a></td> <td><code>a &gt;&gt; b</code></td> <td>Shifts <code>a</code> in binary representation <code>b</code> bits to the right, discarding bits shifted off.</td> </tr> <tr> <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Unsigned_right_shift">Zero-fill right shift</a></td> <td><code>a &gt;&gt;&gt; b</code></td> <td>Shifts <code>a</code> in binary representation <code>b</code> bits to the right, discarding bits shifted off, and shifting in zeros from the left.</td> </tr> </tbody> </table></figure></div></section><section aria-labelledby="bitwise_logical_operators"><h3 id="bitwise_logical_operators"><a href="#bitwise_logical_operators">Bitwise logical operators</a></h3><div class="section-content"><p>Conceptually, the bitwise logical operators work as follows:</p> <ul> <li> <p>The operands are converted to thirty-two-bit integers and expressed by a series of bits (zeros and ones). Numbers with more than 32 bits get their most significant bits discarded. For example, the following integer with more than 32 bits will be converted to a 32-bit integer:</p> <pre class="brush: plain notranslate">Before: 1110 0110 1111 1010 0000 0000 0000 0110 0000 0000 0001 After: 1010 0000 0000 0000 0110 0000 0000 0001 </pre> </li> <li> <p>Each bit in the first operand is paired with the corresponding bit in the second operand: first bit to first bit, second bit to second bit, and so on.</p> </li> <li> <p>The operator is applied to each pair of bits, and the result is constructed bitwise.</p> </li> </ul> <p>For example, the binary representation of nine is 1001, and the binary representation of fifteen is 1111. So, when the bitwise operators are applied to these values, the results are as follows:</p> <figure class="table-container"><table> <thead> <tr> <th>Expression</th> <th>Result</th> <th>Binary Description</th> </tr> </thead> <tbody> <tr> <td><code>15 &amp; 9</code></td> <td><code>9</code></td> <td><code>1111 &amp; 1001 = 1001</code></td> </tr> <tr> <td><code>15 | 9</code></td> <td><code>15</code></td> <td><code>1111 | 1001 = 1111</code></td> </tr> <tr> <td><code>15 ^ 9</code></td> <td><code>6</code></td> <td><code>1111 ^ 1001 = 0110</code></td> </tr> <tr> <td><code>~15</code></td> <td><code>-16</code></td> <td><code>~ 0000 0000 … 0000 1111 = 1111 1111 … 1111 0000</code></td> </tr> <tr> <td><code>~9</code></td> <td><code>-10</code></td> <td><code>~ 0000 0000 … 0000 1001 = 1111 1111 … 1111 0110</code></td> </tr> </tbody> </table></figure> <p>Note that all 32 bits are inverted using the Bitwise NOT operator, and that values with the most significant (left-most) bit set to 1 represent negative numbers (two's-complement representation). <code>~x</code> evaluates to the same value that <code>-x - 1</code> evaluates to.</p></div></section><section aria-labelledby="bitwise_shift_operators"><h3 id="bitwise_shift_operators"><a href="#bitwise_shift_operators">Bitwise shift operators</a></h3><div class="section-content"><p>The bitwise shift operators take two operands: the first is a quantity to be shifted, and the second specifies the number of bit positions by which the first operand is to be shifted. The direction of the shift operation is controlled by the operator used.</p> <p>Shift operators convert their operands to thirty-two-bit integers and return a result of either type <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number"><code>Number</code></a> or <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt"><code>BigInt</code></a>: specifically, if the type of the left operand is <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt"><code>BigInt</code></a>, they return <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt"><code>BigInt</code></a>; otherwise, they return <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number"><code>Number</code></a>.</p> <p>The shift operators are listed in the following table.</p> <figure class="table-container"><table class="fullwidth-table"> <caption> Bitwise shift operators </caption> <thead> <tr> <th scope="col">Operator</th> <th scope="col">Description</th> <th scope="col">Example</th> </tr> </thead> <tbody> <tr> <td> <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Left_shift">Left shift</a><br>(<code>&lt;&lt;</code>) </td> <td> This operator shifts the first operand the specified number of bits to the left. Excess bits shifted off to the left are discarded. Zero bits are shifted in from the right. </td> <td> <code>9&lt;&lt;2</code> yields 36, because 1001 shifted 2 bits to the left becomes 100100, which is 36. </td> </tr> <tr> <td> <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Right_shift">Sign-propagating right shift</a> (<code>&gt;&gt;</code>) </td> <td> This operator shifts the first operand the specified number of bits to the right. Excess bits shifted off to the right are discarded. Copies of the leftmost bit are shifted in from the left. </td> <td> <code>9&gt;&gt;2</code> yields 2, because 1001 shifted 2 bits to the right becomes 10, which is 2. Likewise, <code>-9&gt;&gt;2</code> yields -3, because the sign is preserved. </td> </tr> <tr> <td> <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Unsigned_right_shift">Zero-fill right shift</a> (<code>&gt;&gt;&gt;</code>) </td> <td> This operator shifts the first operand the specified number of bits to the right. Excess bits shifted off to the right are discarded. Zero bits are shifted in from the left. </td> <td> <code>19&gt;&gt;&gt;2</code> yields 4, because 10011 shifted 2 bits to the right becomes 100, which is 4. For non-negative numbers, zero-fill right shift and sign-propagating right shift yield the same result. </td> </tr> </tbody> </table></figure></div></section><section aria-labelledby="logical_operators"><h2 id="logical_operators"><a href="#logical_operators">Logical operators</a></h2><div class="section-content"><p>Logical operators are typically used with Boolean (logical) values; when they are, they return a Boolean value. However, the <code>&amp;&amp;</code>, <code>||</code>, and <code>??</code> operators actually return the value of one of the specified operands, so if these operators are used with non-Boolean values, they may return a non-Boolean value. As such, they are more adequately called "value selection operators". The logical operators are described in the following table.</p> <figure class="table-container"><table class="fullwidth-table"> <caption> Logical operators </caption> <thead> <tr> <th scope="col">Operator</th> <th scope="col">Usage</th> <th scope="col">Description</th> </tr> </thead> <tbody> <tr> <td> <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Logical_AND">Logical AND</a> (<code>&amp;&amp;</code>) </td> <td><code>expr1 &amp;&amp; expr2</code></td> <td> Returns <code>expr1</code> if it can be converted to <code>false</code>; otherwise, returns <code>expr2</code>. Thus, when used with Boolean values, <code>&amp;&amp;</code> returns <code>true</code> if both operands are true; otherwise, returns <code>false</code>. </td> </tr> <tr> <td> <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR">Logical OR</a> (<code>||</code>) </td> <td><code>expr1 || expr2</code></td> <td> Returns <code>expr1</code> if it can be converted to <code>true</code>; otherwise, returns <code>expr2</code>. Thus, when used with Boolean values, <code>||</code> returns <code>true</code> if either operand is true; if both are false, returns <code>false</code>. </td> </tr> <tr> <td> <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing">Nullish coalescing operator</a> (<code>??</code>) </td> <td><code>expr1 ?? expr2</code></td> <td> Returns <code>expr1</code> if it is neither <code>null</code> nor <code>undefined</code>; otherwise, returns <code>expr2</code>. </td> </tr> <tr> <td> <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Logical_NOT">Logical NOT</a> (<code>!</code>) </td> <td><code>!expr</code></td> <td> Returns <code>false</code> if its single operand can be converted to <code>true</code>; otherwise, returns <code>true</code>. </td> </tr> </tbody> </table></figure> <p>Examples of expressions that can be converted to <code>false</code> are those that evaluate to <code>null</code>, <code>0</code>, <code>0n</code>, <code>NaN</code>, the empty string (<code>""</code>), or <code>undefined</code>.</p> <p>The following code shows examples of the <code>&amp;&amp;</code> (logical AND) operator.</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>const a1 = true &amp;&amp; true; // t &amp;&amp; t returns true const a2 = true &amp;&amp; false; // t &amp;&amp; f returns false const a3 = false &amp;&amp; true; // f &amp;&amp; t returns false const a4 = false &amp;&amp; 3 === 4; // f &amp;&amp; f returns false const a5 = "Cat" &amp;&amp; "Dog"; // t &amp;&amp; t returns Dog const a6 = false &amp;&amp; "Cat"; // f &amp;&amp; t returns false const a7 = "Cat" &amp;&amp; false; // t &amp;&amp; f returns false </code></pre></div> <p>The following code shows examples of the <code>||</code> (logical OR) operator.</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>const o1 = true || true; // t || t returns true const o2 = false || true; // f || t returns true const o3 = true || false; // t || f returns true const o4 = false || 3 === 4; // f || f returns false const o5 = "Cat" || "Dog"; // t || t returns Cat const o6 = false || "Cat"; // f || t returns Cat const o7 = "Cat" || false; // t || f returns Cat </code></pre></div> <p>The following code shows examples of the <code>??</code> (nullish coalescing) operator.</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>const n1 = null ?? 1; // 1 const n2 = undefined ?? 2; // 2 const n3 = false ?? 3; // false const n4 = 0 ?? 4; // 0 </code></pre></div> <p>Note how <code>??</code> works like <code>||</code>, but it only returns the second expression when the first one is "<a href="/en-US/docs/Glossary/Nullish">nullish</a>", i.e. <a href="/en-US/docs/Web/JavaScript/Reference/Operators/null"><code>null</code></a> or <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined"><code>undefined</code></a>. <code>??</code> is a better alternative than <code>||</code> for setting defaults for values that might be <code>null</code> or <code>undefined</code>, in particular when values like <code>''</code> or <code>0</code> are valid values and the default should not apply.</p> <p>The following code shows examples of the <code>!</code> (logical NOT) operator.</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>const n1 = !true; // !t returns false const n2 = !false; // !f returns true const n3 = !"Cat"; // !t returns false </code></pre></div></div></section><section aria-labelledby="short-circuit_evaluation"><h3 id="short-circuit_evaluation"><a href="#short-circuit_evaluation">Short-circuit evaluation</a></h3><div class="section-content"><p>As logical expressions are evaluated left to right, they are tested for possible "short-circuit" evaluation using the following rules:</p> <ul> <li><code>falsy &amp;&amp; anything</code> is short-circuit evaluated to the falsy value.</li> <li><code>truthy || anything</code> is short-circuit evaluated to the truthy value.</li> <li><code>nonNullish ?? anything</code> is short-circuit evaluated to the non-nullish value.</li> </ul> <p>The rules of logic guarantee that these evaluations are always correct. Note that the <em>anything</em> part of the above expressions is not evaluated, so any side effects of doing so do not take effect.</p></div></section><section aria-labelledby="bigint_operators"><h2 id="bigint_operators"><a href="#bigint_operators">BigInt operators</a></h2><div class="section-content"><p>Most operators that can be used between numbers can be used between <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt"><code>BigInt</code></a> values as well.</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>// BigInt addition const a = 1n + 2n; // 3n // Division with BigInts round towards zero const b = 1n / 2n; // 0n // Bitwise operations with BigInts do not truncate either side const c = 40000000000000000n &gt;&gt; 2n; // 10000000000000000n </code></pre></div> <p>One exception is <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Unsigned_right_shift">unsigned right shift (<code>&gt;&gt;&gt;</code>)</a>, which is not defined for BigInt values. This is because a BigInt does not have a fixed width, so technically it does not have a "highest bit".</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>const d = 8n &gt;&gt;&gt; 2n; // TypeError: BigInts have no unsigned right shift, use &gt;&gt; instead </code></pre></div> <p>BigInts and numbers are not mutually replaceable — you cannot mix them in calculations.</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js example-bad notranslate"><code>const a = 1n + 2; // TypeError: Cannot mix BigInt and other types </code></pre></div> <p>This is because BigInt is neither a subset nor a superset of numbers. BigInts have higher precision than numbers when representing large integers, but cannot represent decimals, so implicit conversion on either side might lose precision. Use explicit conversion to signal whether you wish the operation to be a number operation or a BigInt one.</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js example-good notranslate"><code>const a = Number(1n) + 2; // 3 const b = 1n + BigInt(2); // 3n </code></pre></div> <p>You can compare BigInts with numbers.</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>const a = 1n &gt; 2; // false const b = 3 &gt; 2n; // true </code></pre></div></div></section><section aria-labelledby="string_operators"><h2 id="string_operators"><a href="#string_operators">String operators</a></h2><div class="section-content"><p>In addition to the comparison operators, which can be used on string values, the concatenation operator (+) concatenates two string values together, returning another string that is the union of the two operand strings.</p> <p>For example,</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>console.log("my " + "string"); // console logs the string "my string". </code></pre></div> <p>The shorthand assignment operator <code>+=</code> can also be used to concatenate strings.</p> <p>For example,</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>let myString = "alpha"; myString += "bet"; // evaluates to "alphabet" and assigns this value to myString. </code></pre></div></div></section><section aria-labelledby="conditional_ternary_operator"><h2 id="conditional_ternary_operator"><a href="#conditional_ternary_operator">Conditional (ternary) operator</a></h2><div class="section-content"><p>The <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_operator">conditional operator</a> is the only JavaScript operator that takes three operands. The operator can have one of two values based on a condition. The syntax is:</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>condition ? val1 : val2 </code></pre></div> <p>If <code>condition</code> is true, the operator has the value of <code>val1</code>. Otherwise it has the value of <code>val2</code>. You can use the conditional operator anywhere you would use a standard operator.</p> <p>For example,</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>const status = age &gt;= 18 ? "adult" : "minor"; </code></pre></div> <p>This statement assigns the value "adult" to the variable <code>status</code> if <code>age</code> is eighteen or more. Otherwise, it assigns the value "minor" to <code>status</code>.</p></div></section><section aria-labelledby="comma_operator"><h2 id="comma_operator"><a href="#comma_operator">Comma operator</a></h2><div class="section-content"><p>The <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Comma_operator">comma operator</a> (<code>,</code>) evaluates both of its operands and returns the value of the last operand. This operator is primarily used inside a <code>for</code> loop, to allow multiple variables to be updated each time through the loop. It is regarded bad style to use it elsewhere, when it is not necessary. Often two separate statements can and should be used instead.</p> <p>For example, if <code>a</code> is a 2-dimensional array with 10 elements on a side, the following code uses the comma operator to update two variables at once. The code prints the values of the diagonal elements in the array:</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>const x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; const a = [x, x, x, x, x]; for (let i = 0, j = 9; i &lt;= j; i++, j--) { // ^ console.log(`a[${i}][${j}]= ${a[i][j]}`); } </code></pre></div></div></section><section aria-labelledby="unary_operators"><h2 id="unary_operators"><a href="#unary_operators">Unary operators</a></h2><div class="section-content"><p>A unary operation is an operation with only one operand.</p></div></section><section aria-labelledby="delete"><h3 id="delete"><a href="#delete">delete</a></h3><div class="section-content"><p>The <a href="/en-US/docs/Web/JavaScript/Reference/Operators/delete"><code>delete</code></a> operator deletes an object's property. The syntax is:</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>delete object.property; delete object[propertyKey]; delete objectName[index]; </code></pre></div> <p>where <code>object</code> is the name of an object, <code>property</code> is an existing property, and <code>propertyKey</code> is a string or symbol referring to an existing property.</p> <p>If the <code>delete</code> operator succeeds, it removes the property from the object. Trying to access it afterwards will yield <code>undefined</code>. The <code>delete</code> operator returns <code>true</code> if the operation is possible; it returns <code>false</code> if the operation is not possible.</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>delete Math.PI; // returns false (cannot delete non-configurable properties) const myObj = { h: 4 }; delete myObj.h; // returns true (can delete user-defined properties) </code></pre></div> <h4 id="deleting_array_elements">Deleting array elements</h4> <p>Since arrays are just objects, it's technically possible to <code>delete</code> elements from them. This is, however, regarded as a bad practice — try to avoid it. When you delete an array property, the array length is not affected and other elements are not re-indexed. To achieve that behavior, it is much better to just overwrite the element with the value <code>undefined</code>. To actually manipulate the array, use the various array methods such as <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice"><code>splice</code></a>.</p></div></section><section aria-labelledby="typeof"><h3 id="typeof"><a href="#typeof">typeof</a></h3><div class="section-content"><p>The <a href="/en-US/docs/Web/JavaScript/Reference/Operators/typeof"><code>typeof</code> operator</a> returns a string indicating the type of the unevaluated operand. <code>operand</code> is the string, variable, keyword, or object for which the type is to be returned. The parentheses are optional.</p> <p>Suppose you define the following variables:</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>const myFun = new Function("5 + 2"); const shape = "round"; const size = 1; const foo = ["Apple", "Mango", "Orange"]; const today = new Date(); </code></pre></div> <p>The <code>typeof</code> operator returns the following results for these variables:</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>typeof myFun; // returns "function" typeof shape; // returns "string" typeof size; // returns "number" typeof foo; // returns "object" typeof today; // returns "object" typeof doesntExist; // returns "undefined" </code></pre></div> <p>For the keywords <code>true</code> and <code>null</code>, the <code>typeof</code> operator returns the following results:</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>typeof true; // returns "boolean" typeof null; // returns "object" </code></pre></div> <p>For a number or string, the <code>typeof</code> operator returns the following results:</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>typeof 62; // returns "number" typeof "Hello world"; // returns "string" </code></pre></div> <p>For property values, the <code>typeof</code> operator returns the type of value the property contains:</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>typeof document.lastModified; // returns "string" typeof window.length; // returns "number" typeof Math.LN2; // returns "number" </code></pre></div> <p>For methods and functions, the <code>typeof</code> operator returns results as follows:</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>typeof blur; // returns "function" typeof eval; // returns "function" typeof parseInt; // returns "function" typeof shape.split; // returns "function" </code></pre></div> <p>For predefined objects, the <code>typeof</code> operator returns results as follows:</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>typeof Date; // returns "function" typeof Function; // returns "function" typeof Math; // returns "object" typeof Option; // returns "function" typeof String; // returns "function" </code></pre></div></div></section><section aria-labelledby="void"><h3 id="void"><a href="#void">void</a></h3><div class="section-content"><p>The <a href="/en-US/docs/Web/JavaScript/Reference/Operators/void"><code>void</code> operator</a> specifies an expression to be evaluated without returning a value. <code>expression</code> is a JavaScript expression to evaluate. The parentheses surrounding the expression are optional, but it is good style to use them to avoid precedence issues.</p></div></section><section aria-labelledby="relational_operators"><h2 id="relational_operators"><a href="#relational_operators">Relational operators</a></h2><div class="section-content"><p>A relational operator compares its operands and returns a Boolean value based on whether the comparison is true.</p></div></section><section aria-labelledby="in"><h3 id="in"><a href="#in">in</a></h3><div class="section-content"><p>The <a href="/en-US/docs/Web/JavaScript/Reference/Operators/in"><code>in</code> operator</a> returns <code>true</code> if the specified property is in the specified object. The syntax is:</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>propNameOrNumber in objectName </code></pre></div> <p>where <code>propNameOrNumber</code> is a string, numeric, or symbol expression representing a property name or array index, and <code>objectName</code> is the name of an object.</p> <p>The following examples show some uses of the <code>in</code> operator.</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>// Arrays const trees = ["redwood", "bay", "cedar", "oak", "maple"]; 0 in trees; // returns true 3 in trees; // returns true 6 in trees; // returns false "bay" in trees; // returns false // (you must specify the index number, not the value at that index) "length" in trees; // returns true (length is an Array property) // built-in objects "PI" in Math; // returns true const myString = new String("coral"); "length" in myString; // returns true // Custom objects const myCar = { make: "Honda", model: "Accord", year: 1998 }; "make" in myCar; // returns true "model" in myCar; // returns true </code></pre></div></div></section><section aria-labelledby="instanceof"><h3 id="instanceof"><a href="#instanceof">instanceof</a></h3><div class="section-content"><p>The <a href="/en-US/docs/Web/JavaScript/Reference/Operators/instanceof"><code>instanceof</code> operator</a> returns <code>true</code> if the specified object is of the specified object type. The syntax is:</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>object instanceof objectType </code></pre></div> <p>where <code>object</code> is the object to test against <code>objectType</code>, and <code>objectType</code> is a constructor representing a type, such as <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map"><code>Map</code></a> or <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array"><code>Array</code></a>.</p> <p>Use <code>instanceof</code> when you need to confirm the type of an object at runtime. For example, when catching exceptions, you can branch to different exception-handling code depending on the type of exception thrown.</p> <p>For example, the following code uses <code>instanceof</code> to determine whether <code>obj</code> is a <code>Map</code> object. Because <code>obj</code> is a <code>Map</code> object, the statements inside the <code>if</code> block execute.</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>const obj = new Map(); if (obj instanceof Map) { // statements to execute } </code></pre></div></div></section><section aria-labelledby="basic_expressions"><h2 id="basic_expressions"><a href="#basic_expressions">Basic expressions</a></h2><div class="section-content"><p>All operators eventually operate on one or more basic expressions. These basic expressions include <a href="/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#declarations">identifiers</a> and <a href="/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#literals">literals</a>, but there are a few other kinds as well. They are briefly introduced below, and their semantics are described in detail in their respective reference sections.</p></div></section><section aria-labelledby="this"><h3 id="this"><a href="#this">this</a></h3><div class="section-content"><p>Use the <a href="/en-US/docs/Web/JavaScript/Reference/Operators/this"><code>this</code> keyword</a> to refer to the current object. In general, <code>this</code> refers to the calling object in a method. Use <code>this</code> either with the dot or the bracket notation:</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>this["propertyName"]; this.propertyName; </code></pre></div> <p>Suppose a function called <code>validate</code> validates an object's <code>value</code> property, given the object and the high and low values:</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>function validate(obj, lowVal, highVal) { if (obj.value &lt; lowVal || obj.value &gt; highVal) { console.log("Invalid Value!"); } } </code></pre></div> <p>You could call <code>validate</code> in each form element's <code>onChange</code> event handler, using <code>this</code> to pass it to the form element, as in the following example:</p> <div class="code-example"><div class="example-header"><span class="language-name">html</span></div><pre class="brush: html notranslate"><code>&lt;p&gt;Enter a number between 18 and 99:&lt;/p&gt; &lt;input type="text" name="age" size="3" onChange="validate(this, 18, 99);" /&gt; </code></pre></div></div></section><section aria-labelledby="grouping_operator"><h3 id="grouping_operator"><a href="#grouping_operator">Grouping operator</a></h3><div class="section-content"><p>The grouping operator <code>( )</code> controls the precedence of evaluation in expressions. For example, you can override multiplication and division first, then addition and subtraction to evaluate addition first.</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>const a = 1; const b = 2; const c = 3; // default precedence a + b * c // 7 // evaluated by default like this a + (b * c) // 7 // now overriding precedence // addition before multiplication (a + b) * c // 9 // which is equivalent to a * c + b * c // 9 </code></pre></div></div></section><section aria-labelledby="property_accessor"><h3 id="property_accessor"><a href="#property_accessor">Property accessor</a></h3><div class="section-content"><p>The <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors">property accessor</a> syntax gets property values on objects, using either dot notation or bracket notation.</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>object.property; object["property"]; </code></pre></div> <p>The <a href="/en-US/docs/Web/JavaScript/Guide/Working_with_objects">working with objects</a> guide goes into more details about object properties.</p></div></section><section aria-labelledby="optional_chaining"><h3 id="optional_chaining"><a href="#optional_chaining">Optional chaining</a></h3><div class="section-content"><p>The <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining">optional chaining</a> syntax (<code>?.</code>) performs the chained operation on an object if it is defined and non-<code>null</code>, and otherwise short-circuits the operation and returns <code>undefined</code>. This allows you to operate on a value that may be <code>null</code> or <code>undefined</code> without causing a <code>TypeError</code>.</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>maybeObject?.property; maybeObject?.[property]; maybeFunction?.(); </code></pre></div></div></section><section aria-labelledby="new"><h3 id="new"><a href="#new">new</a></h3><div class="section-content"><p>You can use the <a href="/en-US/docs/Web/JavaScript/Reference/Operators/new"><code>new</code> operator</a> to create an instance of a user-defined object type or of one of the built-in object types. Use <code>new</code> as follows:</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>const objectName = new ObjectType(param1, param2, /* …, */ paramN); </code></pre></div></div></section><section aria-labelledby="super"><h3 id="super"><a href="#super">super</a></h3><div class="section-content"><p>The <a href="/en-US/docs/Web/JavaScript/Reference/Operators/super"><code>super</code> keyword</a> is used to call functions on an object's parent. It is useful with <a href="/en-US/docs/Web/JavaScript/Reference/Classes">classes</a> to call the parent constructor, for example.</p> <div class="code-example"><div class="example-header"><span class="language-name">js</span></div><pre class="brush: js notranslate"><code>super(args); // calls the parent constructor. super.functionOnParent(args); </code></pre></div> <ul class="prev-next"><li><a class="button secondary" href="/en-US/docs/Web/JavaScript/Guide/Functions"><span class="button-wrap"> Previous </span></a></li><li><a class="button secondary" href="/en-US/docs/Web/JavaScript/Guide/Numbers_and_strings"><span class="button-wrap"> Next </span></a></li></ul></div></section></article><aside class="article-footer"><div class="article-footer-inner"><div class="svg-container"><svg xmlns="http://www.w3.org/2000/svg" width="162" height="162" viewBox="0 0 162 162" fill="none" role="none"><mask id="b" fill="#fff"><path d="M97.203 47.04c8.113-7.886 18.004-13.871 28.906-17.492a78 78 0 0 1 33.969-3.39c11.443 1.39 22.401 5.295 32.024 11.411s17.656 14.28 23.476 23.86c5.819 9.579 9.269 20.318 10.083 31.385a69.85 69.85 0 0 1-5.387 32.44c-4.358 10.272-11.115 19.443-19.747 26.801-8.632 7.359-18.908 12.709-30.034 15.637l-6.17-21.698c7.666-2.017 14.746-5.703 20.694-10.773 5.948-5.071 10.603-11.389 13.606-18.467a48.14 48.14 0 0 0 3.712-22.352c-.561-7.625-2.938-15.025-6.948-21.625s-9.544-12.226-16.175-16.44-14.181-6.904-22.065-7.863a53.75 53.75 0 0 0-23.405 2.336c-7.513 2.495-14.327 6.62-19.918 12.053z"></path></mask><path stroke="url(#a)" stroke-dasharray="6, 6" stroke-width="2" d="M97.203 47.04c8.113-7.886 18.004-13.871 28.906-17.492a78 78 0 0 1 33.969-3.39c11.443 1.39 22.401 5.295 32.024 11.411s17.656 14.28 23.476 23.86c5.819 9.579 9.269 20.318 10.083 31.385a69.85 69.85 0 0 1-5.387 32.44c-4.358 10.272-11.115 19.443-19.747 26.801-8.632 7.359-18.908 12.709-30.034 15.637l-6.17-21.698c7.666-2.017 14.746-5.703 20.694-10.773 5.948-5.071 10.603-11.389 13.606-18.467a48.14 48.14 0 0 0 3.712-22.352c-.561-7.625-2.938-15.025-6.948-21.625s-9.544-12.226-16.175-16.44-14.181-6.904-22.065-7.863a53.75 53.75 0 0 0-23.405 2.336c-7.513 2.495-14.327 6.62-19.918 12.053z" mask="url(#b)" style="stroke:url(#a)" transform="translate(-63.992 -25.587)"></path><ellipse cx="8.066" cy="111.597" fill="var(--background-tertiary)" rx="53.677" ry="53.699" transform="matrix(.71707 -.697 .7243 .6895 0 0)"></ellipse><g clip-path="url(#c)" transform="translate(-63.992 -25.587)"><path fill="#9abff5" d="m144.256 137.379 32.906 12.434a4.41 4.41 0 0 1 2.559 5.667l-9.326 24.679a4.41 4.41 0 0 1-5.667 2.559l-8.226-3.108-2.332 6.17c-.466 1.233-.375 1.883-1.609 1.417l-2.253-.527c-.411-.155-.95-.594-1.206-1.161l-4.734-10.484-12.545-4.741a4.41 4.41 0 0 1-2.559-5.667l9.325-24.679a4.41 4.41 0 0 1 5.667-2.559m9.961 29.617 8.227 3.108 3.264-8.638-.498-6.768-4.113-1.555.548 7.258-4.319-1.632zm-12.339-4.663 8.226 3.108 3.264-8.637-.498-6.769-4.113-1.554.548 7.257-4.319-1.632z"></path></g><g clip-path="url(#d)" transform="translate(-63.992 -25.587)"><path fill="#81b0f3" d="M135.35 60.136 86.67 41.654c-3.346-1.27-7.124.428-8.394 3.775L64.414 81.938c-1.27 3.347.428 7.125 3.774 8.395l12.17 4.62-3.465 9.128c-.693 1.826-1.432 2.457.394 3.15l3.014 1.625c.609.231 1.637.274 2.477-.104l15.53-6.983 18.56 7.047c3.346 1.27 7.124-.428 8.395-3.775l13.862-36.51c1.27-3.346-.428-7.124-3.775-8.395M95.261 83.207l-12.17-4.62 4.852-12.779 7.19-7.017 6.085 2.31-7.725 7.51 6.389 2.426zm18.255 6.93-12.17-4.62 4.852-12.778 7.189-7.017 6.085 2.31-7.725 7.51 6.39 2.426z"></path></g><defs><clipPath id="c"><path fill="#fff" d="m198.638 146.586-65.056-24.583-24.583 65.057 65.056 24.582z"></path></clipPath><clipPath id="d"><path fill="#fff" d="m66.438 14.055 96.242 36.54-36.54 96.243-96.243-36.54z"></path></clipPath><linearGradient id="a" x1="97.203" x2="199.995" y1="47.04" y2="152.793" gradientUnits="userSpaceOnUse"><stop stop-color="#086DFC"></stop><stop offset="0.246" stop-color="#2C81FA"></stop><stop offset="0.516" stop-color="#5497F8"></stop><stop offset="0.821" stop-color="#80B0F6"></stop><stop offset="1" stop-color="#9ABFF5"></stop></linearGradient></defs></svg></div><h2>Help improve MDN</h2><fieldset class="feedback"><label>Was this page helpful to you?</label><div class="button-container"><button type="button" class="button primary has-icon yes"><span class="button-wrap"><span class="icon icon-thumbs-up "></span>Yes</span></button><button type="button" class="button primary has-icon no"><span class="button-wrap"><span class="icon icon-thumbs-down "></span>No</span></button></div></fieldset><a class="contribute" href="https://github.com/mdn/content/blob/main/CONTRIBUTING.md" title="This will take you to our contribution guidelines on GitHub." target="_blank" rel="noopener noreferrer">Learn how to contribute</a>.<p class="last-modified-date">This page was last modified on<!-- --> <time dateTime="2025-01-20T22:28:20.000Z">Jan 20, 2025</time> by<!-- --> <a href="/en-US/docs/Web/JavaScript/Guide/Expressions_and_operators/contributors.txt" rel="nofollow">MDN contributors</a>.</p><div id="on-github" class="on-github"><a href="https://github.com/mdn/content/blob/main/files/en-us/web/javascript/guide/expressions_and_operators/index.md?plain=1" title="Folder: en-us/web/javascript/guide/expressions_and_operators (Opens in a new tab)" target="_blank" rel="noopener noreferrer">View this page on GitHub</a> <!-- -->•<!-- --> <a href="https://github.com/mdn/content/issues/new?template=page-report.yml&amp;mdn-url=https%3A%2F%2Fdeveloper.mozilla.org%2Fen-US%2Fdocs%2FWeb%2FJavaScript%2FGuide%2FExpressions_and_operators&amp;metadata=%3C%21--+Do+not+make+changes+below+this+line+--%3E%0A%3Cdetails%3E%0A%3Csummary%3EPage+report+details%3C%2Fsummary%3E%0A%0A*+Folder%3A+%60en-us%2Fweb%2Fjavascript%2Fguide%2Fexpressions_and_operators%60%0A*+MDN+URL%3A+https%3A%2F%2Fdeveloper.mozilla.org%2Fen-US%2Fdocs%2FWeb%2FJavaScript%2FGuide%2FExpressions_and_operators%0A*+GitHub+URL%3A+https%3A%2F%2Fgithub.com%2Fmdn%2Fcontent%2Fblob%2Fmain%2Ffiles%2Fen-us%2Fweb%2Fjavascript%2Fguide%2Fexpressions_and_operators%2Findex.md%0A*+Last+commit%3A+https%3A%2F%2Fgithub.com%2Fmdn%2Fcontent%2Fcommit%2Fa4e9bce1e8bac1b845b32536e0e44f335233eab6%0A*+Document+last+modified%3A+2025-01-20T22%3A28%3A20.000Z%0A%0A%3C%2Fdetails%3E" title="This will take you to GitHub to file a new issue." target="_blank" rel="noopener noreferrer">Report a problem with this content</a></div></div></aside></main></div></div><footer id="nav-footer" class="page-footer"><div class="page-footer-grid"><div class="page-footer-logo-col"><a href="/" class="mdn-footer-logo" aria-label="MDN homepage"><svg width="48" height="17" viewBox="0 0 48 17" fill="none" xmlns="http://www.w3.org/2000/svg"><title id="mdn-footer-logo-svg">MDN logo</title><path d="M20.04 16.512H15.504V10.416C15.504 9.488 15.344 8.824 15.024 8.424C14.72 8.024 14.264 7.824 13.656 7.824C12.92 7.824 12.384 8.064 12.048 8.544C11.728 9.024 11.568 9.64 11.568 10.392V14.184H13.008V16.512H8.472V10.416C8.472 9.488 8.312 8.824 7.992 8.424C7.688 8.024 7.232 7.824 6.624 7.824C5.872 7.824 5.336 8.064 5.016 8.544C4.696 9.024 4.536 9.64 4.536 10.392V14.184H6.6V16.512H0V14.184H1.44V8.04H0.024V5.688H4.536V7.32C5.224 6.088 6.32 5.472 7.824 5.472C8.608 5.472 9.328 5.664 9.984 6.048C10.64 6.432 11.096 7.016 11.352 7.8C11.992 6.248 13.168 5.472 14.88 5.472C15.856 5.472 16.72 5.776 17.472 6.384C18.224 6.992 18.6 7.936 18.6 9.216V14.184H20.04V16.512Z" fill="currentColor"></path><path d="M33.6714 16.512H29.1354V14.496C28.8314 15.12 28.3834 15.656 27.7914 16.104C27.1994 16.536 26.4154 16.752 25.4394 16.752C24.0154 16.752 22.8954 16.264 22.0794 15.288C21.2634 14.312 20.8554 12.984 20.8554 11.304C20.8554 9.688 21.2554 8.312 22.0554 7.176C22.8554 6.04 24.0634 5.472 25.6794 5.472C26.5594 5.472 27.2794 5.648 27.8394 6C28.3994 6.352 28.8314 6.8 29.1354 7.344V2.352H26.9754V0H32.2314V14.184H33.6714V16.512ZM29.1354 11.04V10.776C29.1354 9.88 28.8954 9.184 28.4154 8.688C27.9514 8.176 27.3674 7.92 26.6634 7.92C25.9754 7.92 25.3674 8.176 24.8394 8.688C24.3274 9.2 24.0714 10.008 24.0714 11.112C24.0714 12.152 24.3114 12.944 24.7914 13.488C25.2714 14.032 25.8394 14.304 26.4954 14.304C27.3114 14.304 27.9514 13.96 28.4154 13.272C28.8954 12.584 29.1354 11.84 29.1354 11.04Z" fill="currentColor"></path><path d="M47.9589 16.512H41.9829V14.184H43.4229V10.416C43.4229 9.488 43.2629 8.824 42.9429 8.424C42.6389 8.024 42.1829 7.824 41.5749 7.824C40.8389 7.824 40.2709 8.056 39.8709 8.52C39.4709 8.968 39.2629 9.56 39.2469 10.296V14.184H40.6869V16.512H34.7109V14.184H36.1509V8.04H34.5909V5.688H39.2469V7.344C39.9669 6.096 41.1269 5.472 42.7269 5.472C43.7509 5.472 44.6389 5.776 45.3909 6.384C46.1429 6.992 46.5189 7.936 46.5189 9.216V14.184H47.9589V16.512Z" fill="currentColor"></path></svg></a><p>Your blueprint for a better internet.</p><ul class="social-icons"><li><a href="https://mastodon.social/@mdn" target="_blank" rel="me noopener noreferrer"><span class="icon icon-mastodon"></span><span class="visually-hidden">MDN on Mastodon</span></a></li><li><a href="https://twitter.com/mozdevnet" target="_blank" rel="noopener noreferrer"><span class="icon icon-twitter-x"></span><span class="visually-hidden">MDN on X (formerly Twitter)</span></a></li><li><a href="https://github.com/mdn/" target="_blank" rel="noopener noreferrer"><span class="icon icon-github-mark-small"></span><span class="visually-hidden">MDN on GitHub</span></a></li><li><a href="/en-US/blog/rss.xml" target="_blank"><span class="icon icon-feed"></span><span class="visually-hidden">MDN Blog RSS Feed</span></a></li></ul></div><div class="page-footer-nav-col-1"><h2 class="footer-nav-heading">MDN</h2><ul class="footer-nav-list"><li class="footer-nav-item"><a href="/en-US/about">About</a></li><li class="footer-nav-item"><a href="/en-US/blog/">Blog</a></li><li class="footer-nav-item"><a href="https://www.mozilla.org/en-US/careers/listings/?team=ProdOps" target="_blank" rel="noopener noreferrer">Careers</a></li><li class="footer-nav-item"><a href="/en-US/advertising">Advertise with us</a></li></ul></div><div class="page-footer-nav-col-2"><h2 class="footer-nav-heading">Support</h2><ul class="footer-nav-list"><li class="footer-nav-item"><a class="footer-nav-link" href="https://support.mozilla.org/products/mdn-plus">Product help</a></li><li class="footer-nav-item"><a class="footer-nav-link" href="/en-US/docs/MDN/Community/Issues">Report an issue</a></li></ul></div><div class="page-footer-nav-col-3"><h2 class="footer-nav-heading">Our communities</h2><ul class="footer-nav-list"><li class="footer-nav-item"><a class="footer-nav-link" href="/en-US/community">MDN Community</a></li><li class="footer-nav-item"><a class="footer-nav-link" href="https://discourse.mozilla.org/c/mdn/236" target="_blank" rel="noopener noreferrer">MDN Forum</a></li><li class="footer-nav-item"><a class="footer-nav-link" href="/discord" target="_blank" rel="noopener noreferrer">MDN Chat</a></li></ul></div><div class="page-footer-nav-col-4"><h2 class="footer-nav-heading">Developers</h2><ul class="footer-nav-list"><li class="footer-nav-item"><a class="footer-nav-link" href="/en-US/docs/Web">Web Technologies</a></li><li class="footer-nav-item"><a class="footer-nav-link" href="/en-US/docs/Learn">Learn Web Development</a></li><li class="footer-nav-item"><a class="footer-nav-link" href="/en-US/plus">MDN Plus</a></li><li class="footer-nav-item"><a href="https://hacks.mozilla.org/" target="_blank" rel="noopener noreferrer">Hacks Blog</a></li></ul></div><div class="page-footer-moz"><a href="https://www.mozilla.org/" class="footer-moz-logo-link" target="_blank" rel="noopener noreferrer"><svg xmlns="http://www.w3.org/2000/svg" width="137" height="32" fill="none" viewBox="0 0 267.431 62.607"><path fill="currentColor" d="m13.913 23.056 5.33 25.356h2.195l5.33-25.356h14.267v38.976h-7.578V29.694h-2.194l-7.264 32.337h-7.343L9.418 29.694H7.223v32.337H-.354V23.056Zm47.137 9.123c9.12 0 14.423 5.385 14.423 15.214s-5.33 15.214-14.423 15.214c-9.12 0-14.423-5.385-14.423-15.214 0-9.855 5.304-15.214 14.423-15.214m0 24.363c4.285 0 6.428-2.196 6.428-7.032v-4.287c0-4.836-2.143-7.032-6.428-7.032s-6.428 2.196-6.428 7.032v4.287c0 4.836 2.143 7.032 6.428 7.032m18.473-.157 15.47-18.01h-15.26v-5.647h24.352v5.646L88.616 56.385h15.704v5.646H79.523Zm29.318-23.657h11.183V62.03h-7.578V38.375h-3.632v-5.646zm3.605-9.672h7.578v5.646h-7.578zm13.17 0h11.21v38.976h-7.578v-33.33h-3.632zm16.801 0H153.6v38.976h-7.577v-33.33h-3.632v-5.646zm29.03 9.123c4.442 0 7.394 2.143 8.231 5.881h2.194v-5.332h9.276v5.646h-3.632v18.011h3.632v5.646h-4.442c-3.135 0-4.834-1.699-4.834-4.836V56.7h-2.194c-.81 3.738-3.789 5.881-8.23 5.881-6.978 0-11.916-5.829-11.916-15.214 0-9.384 4.938-15.187 11.915-15.187m2.3 24.363c4.284 0 6.192-2.196 6.192-7.032v-4.287c0-4.836-1.908-7.032-6.193-7.032-4.18 0-6.193 2.196-6.193 7.032v4.287c0 4.836 2.012 7.032 6.193 7.032m48.34 5.489h-7.577V0h7.577zm6.585-29.643h32.165v-2.196l-21.295-7.634v-6.143l21.295-7.633V6.588h-25.345V0h32.165v12.522l-17.35 5.881V20.6l17.35 5.882v12.521h-38.985zm0-25.801h6.794v6.796h-6.794z"></path></svg></a><ul class="footer-moz-list"><li class="footer-moz-item"><a href="https://www.mozilla.org/privacy/websites/" class="footer-moz-link" target="_blank" rel="noopener noreferrer">Website Privacy Notice</a></li><li class="footer-moz-item"><a href="https://www.mozilla.org/privacy/websites/#cookies" class="footer-moz-link" target="_blank" rel="noopener noreferrer">Cookies</a></li><li class="footer-moz-item"><a href="https://www.mozilla.org/about/legal/terms/mozilla" class="footer-moz-link" target="_blank" rel="noopener noreferrer">Legal</a></li><li class="footer-moz-item"><a href="https://www.mozilla.org/about/governance/policies/participation/" class="footer-moz-link" target="_blank" rel="noopener noreferrer">Community Participation Guidelines</a></li></ul></div><div class="page-footer-legal"><p id="license" class="page-footer-legal-text">Visit<!-- --> <a href="https://www.mozilla.org" target="_blank" rel="noopener noreferrer">Mozilla Corporation’s</a> <!-- -->not-for-profit parent, the<!-- --> <a target="_blank" rel="noopener noreferrer" href="https://foundation.mozilla.org/">Mozilla Foundation</a>.<br/>Portions of this content are ©1998–<!-- -->2025<!-- --> by individual mozilla.org contributors. Content available under<!-- --> <a href="/en-US/docs/MDN/Writing_guidelines/Attrib_copyright_license">a Creative Commons license</a>.</p></div></div></footer></div><script type="application/json" id="hydration">{"url":"/en-US/docs/Web/JavaScript/Guide/Expressions_and_operators","doc":{"body":[{"type":"prose","value":{"id":null,"title":null,"isH3":false,"content":"<ul class=\"prev-next\"><li><a class=\"button secondary\" href=\"/en-US/docs/Web/JavaScript/Guide/Functions\"><span class=\"button-wrap\"> Previous </span></a></li><li><a class=\"button secondary\" href=\"/en-US/docs/Web/JavaScript/Guide/Numbers_and_strings\"><span class=\"button-wrap\"> Next </span></a></li></ul>\n<p>This chapter describes JavaScript's expressions and operators, including assignment, comparison, arithmetic, bitwise, logical, string, ternary and more.</p>\n<p>At a high level, an <em>expression</em> is a valid unit of code that resolves to a value. There are two types of expressions: those that have side effects (such as assigning values) and those that purely <em>evaluate</em>.</p>\n<p>The expression <code>x = 7</code> is an example of the first type. This expression uses the <code>=</code> <em>operator</em> to assign the value seven to the variable <code>x</code>. The expression itself evaluates to <code>7</code>.</p>\n<p>The expression <code>3 + 4</code> is an example of the second type. This expression uses the <code>+</code> operator to add <code>3</code> and <code>4</code> together and produces a value, <code>7</code>. However, if it's not eventually part of a bigger construct (for example, a <a href=\"/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#declarations\">variable declaration</a> like <code>const z = 3 + 4</code>), its result will be immediately discarded — this is usually a programmer mistake because the evaluation doesn't produce any effects.</p>\n<p>As the examples above also illustrate, all complex expressions are joined by <em>operators</em>, such as <code>=</code> and <code>+</code>. In this section, we will introduce the following operators:</p>\n<ul>\n<li><a href=\"#assignment_operators\">Assignment operators</a></li>\n<li><a href=\"#comparison_operators\">Comparison operators</a></li>\n<li><a href=\"#arithmetic_operators\">Arithmetic operators</a></li>\n<li><a href=\"#bitwise_operators\">Bitwise operators</a></li>\n<li><a href=\"#logical_operators\">Logical operators</a></li>\n<li><a href=\"#bigint_operators\">BigInt operators</a></li>\n<li><a href=\"#string_operators\">String operators</a></li>\n<li><a href=\"#conditional_ternary_operator\">Conditional (ternary) operator</a></li>\n<li><a href=\"#comma_operator\">Comma operator</a></li>\n<li><a href=\"#unary_operators\">Unary operators</a></li>\n<li><a href=\"#relational_operators\">Relational operators</a></li>\n</ul>\n<p>These operators join operands either formed by higher-precedence operators or one of the <a href=\"#basic_expressions\">basic expressions</a>. A complete and detailed list of operators and expressions is also available in the <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators\">reference</a>.</p>\n<p>The <em>precedence</em> of operators determines the order they are applied when evaluating an expression. For example:</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>const x = 1 + 2 * 3;\nconst y = 2 * 3 + 1;\n</code></pre></div>\n<p>Despite <code>*</code> and <code>+</code> coming in different orders, both expressions would result in <code>7</code> because <code>*</code> has precedence over <code>+</code>, so the <code>*</code>-joined expression will always be evaluated first. You can override operator precedence by using parentheses (which creates a <a href=\"#grouping_operator\">grouped expression</a> — the basic expression). To see a complete table of operator precedence as well as various caveats, see the <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Operator_precedence#table\">Operator Precedence Reference</a> page.</p>\n<p>JavaScript has both <em>binary</em> and <em>unary</em> operators, and one special ternary operator, the conditional operator.\nA binary operator requires two operands, one before the operator and one after the operator:</p>\n<pre class=\"brush: plain notranslate\">operand1 operator operand2\n</pre>\n<p>For example, <code>3 + 4</code> or <code>x * y</code>. This form is called an <em>infix</em> binary operator, because the operator is placed between two operands. All binary operators in JavaScript are infix.</p>\n<p>A unary operator requires a single operand, either before or after the operator:</p>\n<pre class=\"brush: plain notranslate\">operator operand\noperand operator\n</pre>\n<p>For example, <code>x++</code> or <code>++x</code>. The <code>operator operand</code> form is called a <em>prefix</em> unary operator, and the <code>operand operator</code> form is called a <em>postfix</em> unary operator. <code>++</code> and <code>--</code> are the only postfix operators in JavaScript — all other operators, like <code>!</code>, <code>typeof</code>, etc. are prefix.</p>"}},{"type":"prose","value":{"id":"assignment_operators","title":"Assignment operators","isH3":false,"content":"<p>An assignment operator assigns a value to its left operand based on the value of its right operand.\nThe simple assignment operator is equal (<code>=</code>), which assigns the value of its right operand to its left operand.\nThat is, <code>x = f()</code> is an assignment expression that assigns the value of <code>f()</code> to <code>x</code>.</p>\n<p>There are also compound assignment operators that are shorthand for the operations listed in the following table:</p>\n<figure class=\"table-container\"><table>\n<thead>\n<tr>\n<th>Name</th>\n<th>Shorthand operator</th>\n<th>Meaning</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Assignment\">Assignment</a></td>\n<td><code>x = f()</code></td>\n<td><code>x = f()</code></td>\n</tr>\n<tr>\n<td><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Addition_assignment\">Addition assignment</a></td>\n<td><code>x += f()</code></td>\n<td><code>x = x + f()</code></td>\n</tr>\n<tr>\n<td><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Subtraction_assignment\">Subtraction assignment</a></td>\n<td><code>x -= f()</code></td>\n<td><code>x = x - f()</code></td>\n</tr>\n<tr>\n<td><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Multiplication_assignment\">Multiplication assignment</a></td>\n<td><code>x *= f()</code></td>\n<td><code>x = x * f()</code></td>\n</tr>\n<tr>\n<td><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Division_assignment\">Division assignment</a></td>\n<td><code>x /= f()</code></td>\n<td><code>x = x / f()</code></td>\n</tr>\n<tr>\n<td><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Remainder_assignment\">Remainder assignment</a></td>\n<td><code>x %= f()</code></td>\n<td><code>x = x % f()</code></td>\n</tr>\n<tr>\n<td><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation_assignment\">Exponentiation assignment</a></td>\n<td><code>x **= f()</code></td>\n<td><code>x = x ** f()</code></td>\n</tr>\n<tr>\n<td><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Left_shift_assignment\">Left shift assignment</a></td>\n<td><code>x &lt;&lt;= f()</code></td>\n<td><code>x = x &lt;&lt; f()</code></td>\n</tr>\n<tr>\n<td><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Right_shift_assignment\">Right shift assignment</a></td>\n<td><code>x &gt;&gt;= f()</code></td>\n<td><code>x = x &gt;&gt; f()</code></td>\n</tr>\n<tr>\n<td><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Unsigned_right_shift_assignment\">Unsigned right shift assignment</a></td>\n<td><code>x &gt;&gt;&gt;= f()</code></td>\n<td><code>x = x &gt;&gt;&gt; f()</code></td>\n</tr>\n<tr>\n<td><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_AND_assignment\">Bitwise AND assignment</a></td>\n<td><code>x &amp;= f()</code></td>\n<td><code>x = x &amp; f()</code></td>\n</tr>\n<tr>\n<td><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_XOR_assignment\">Bitwise XOR assignment</a></td>\n<td><code>x ^= f()</code></td>\n<td><code>x = x ^ f()</code></td>\n</tr>\n<tr>\n<td><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_OR_assignment\">Bitwise OR assignment</a></td>\n<td><code>x |= f()</code></td>\n<td><code>x = x | f()</code></td>\n</tr>\n<tr>\n<td><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Logical_AND_assignment\">Logical AND assignment</a></td>\n<td><code>x &amp;&amp;= f()</code></td>\n<td><code>x &amp;&amp; (x = f())</code></td>\n</tr>\n<tr>\n<td><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR_assignment\">Logical OR assignment</a></td>\n<td><code>x ||= f()</code></td>\n<td><code>x || (x = f())</code></td>\n</tr>\n<tr>\n<td><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_assignment\">Nullish coalescing assignment</a></td>\n<td><code>x ??= f()</code></td>\n<td><code>x ?? (x = f())</code></td>\n</tr>\n</tbody>\n</table></figure>"}},{"type":"prose","value":{"id":"assigning_to_properties","title":"Assigning to properties","isH3":true,"content":"<p>If an expression evaluates to an <a href=\"/en-US/docs/Web/JavaScript/Guide/Working_with_objects\">object</a>, then the left-hand side of an assignment expression may make assignments to properties of that expression.\nFor example:</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>const obj = {};\n\nobj.x = 3;\nconsole.log(obj.x); // Prints 3.\nconsole.log(obj); // Prints { x: 3 }.\n\nconst key = \"y\";\nobj[key] = 5;\nconsole.log(obj[key]); // Prints 5.\nconsole.log(obj); // Prints { x: 3, y: 5 }.\n</code></pre></div>\n<p>For more information about objects, read <a href=\"/en-US/docs/Web/JavaScript/Guide/Working_with_objects\">Working with Objects</a>.</p>\n<p>If an expression does not evaluate to an object, then assignments to properties of that expression do not assign:</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>const val = 0;\nval.x = 3;\n\nconsole.log(val.x); // Prints undefined.\nconsole.log(val); // Prints 0.\n</code></pre></div>\n<p>In <a href=\"/en-US/docs/Web/JavaScript/Reference/Strict_mode#converting_mistakes_into_errors\">strict mode</a>, the code above throws, because one cannot assign properties to primitives.</p>\n<p>It is an error to assign values to unmodifiable properties or to properties of an expression without properties (<code>null</code> or <code>undefined</code>).</p>"}},{"type":"prose","value":{"id":"destructuring","title":"Destructuring","isH3":true,"content":"<p>For more complex assignments, the <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment\">destructuring assignment</a> syntax is a JavaScript expression that makes it possible to extract data from arrays or objects using a syntax that mirrors the construction of array and\nobject literals.</p>\n<p>Without destructuring, it takes multiple statements to extract values from arrays and objects:</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>const foo = [\"one\", \"two\", \"three\"];\n\nconst one = foo[0];\nconst two = foo[1];\nconst three = foo[2];\n</code></pre></div>\n<p>With destructuring, you can extract multiple values into distinct variables using a single statement:</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>const [one, two, three] = foo;\n</code></pre></div>"}},{"type":"prose","value":{"id":"evaluation_and_nesting","title":"Evaluation and nesting","isH3":true,"content":"<p>In general, assignments are used within a variable declaration (i.e., with <a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/const\"><code>const</code></a>, <a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/let\"><code>let</code></a>, or <a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/var\"><code>var</code></a>) or as standalone statements.</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>// Declares a variable x and initializes it to the result of f().\n// The result of the x = f() assignment expression is discarded.\nlet x = f();\n\nx = g(); // Reassigns the variable x to the result of g().\n</code></pre></div>\n<p>However, like other expressions, assignment expressions like <code>x = f()</code> evaluate into a result value.\nAlthough this result value is usually not used, it can then be used by another expression.</p>\n<p>Chaining assignments or nesting assignments in other expressions can result in surprising behavior.\nFor this reason, some JavaScript style guides <a href=\"https://github.com/airbnb/javascript/blob/master/README.md#variables--no-chain-assignment\" class=\"external\" target=\"_blank\">discourage chaining or nesting assignments</a>.\nNevertheless, assignment chaining and nesting may occur sometimes, so it is important to be able to understand how they work.</p>\n<p>By chaining or nesting an assignment expression, its result can itself be assigned to another variable.\nIt can be logged, it can be put inside an array literal or function call, and so on.</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>let x;\nconst y = (x = f()); // Or equivalently: const y = x = f();\nconsole.log(y); // Logs the return value of the assignment x = f().\n\nconsole.log(x = f()); // Logs the return value directly.\n\n// An assignment expression can be nested in any place\n// where expressions are generally allowed,\n// such as array literals' elements or as function calls' arguments.\nconsole.log([0, x = f(), 0]);\nconsole.log(f(0, x = f(), 0));\n</code></pre></div>\n<p>The evaluation result matches the expression to the right of the <code>=</code> sign in the\n\"Meaning\" column of the table above. That means that <code>x = f()</code> evaluates into\nwhatever <code>f()</code>'s result is, <code>x += f()</code> evaluates into the resulting sum <code>x + f()</code>,\n<code>x **= f()</code> evaluates into the resulting power <code>x ** f()</code>, and so on.</p>\n<p>In the case of logical assignments, <code>x &amp;&amp;= f()</code>,\n<code>x ||= f()</code>, and <code>x ??= f()</code>, the return value is that of the\nlogical operation without the assignment, so <code>x &amp;&amp; f()</code>,\n<code>x || f()</code>, and <code>x ?? f()</code>, respectively.</p>\n<p>When chaining these expressions without parentheses or other grouping operators\nlike array literals, the assignment expressions are <strong>grouped right to left</strong>\n(they are <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Operator_precedence#precedence_and_associativity\">right-associative</a>), but they are <strong>evaluated left to right</strong>.</p>\n<p>Note that, for all assignment operators other than <code>=</code> itself,\nthe resulting values are always based on the operands' values <em>before</em>\nthe operation.</p>\n<p>For example, assume that the following functions <code>f</code> and <code>g</code>\nand the variables <code>x</code> and <code>y</code> have been declared:</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>function f() {\n console.log(\"F!\");\n return 2;\n}\nfunction g() {\n console.log(\"G!\");\n return 3;\n}\nlet x, y;\n</code></pre></div>\n<p>Consider these three examples:</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>y = x = f();\ny = [f(), x = g()];\nx[f()] = g();\n</code></pre></div>\n<h4 id=\"evaluation_example_1\">Evaluation example 1</h4>\n<p><code>y = x = f()</code> is equivalent to <code>y = (x = f())</code>,\nbecause the assignment operator <code>=</code> is <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Operator_precedence#precedence_and_associativity\">right-associative</a>.\nHowever, it evaluates from left to right:</p>\n<ol>\n<li>The assignment expression <code>y = x = f()</code> starts to evaluate.\n<ol>\n<li>The <code>y</code> on this assignment's left-hand side evaluates\ninto a reference to the variable named <code>y</code>.</li>\n<li>The assignment expression <code>x = f()</code> starts to evaluate.\n<ol>\n<li>The <code>x</code> on this assignment's left-hand side evaluates\ninto a reference to the variable named <code>x</code>.</li>\n<li>The function call <code>f()</code> prints \"F!\" to the console and\nthen evaluates to the number <code>2</code>.</li>\n<li>That <code>2</code> result from <code>f()</code> is assigned to <code>x</code>.</li>\n</ol>\n</li>\n<li>The assignment expression <code>x = f()</code> has now finished evaluating;\nits result is the new value of <code>x</code>, which is <code>2</code>.</li>\n<li>That <code>2</code> result in turn is also assigned to <code>y</code>.</li>\n</ol>\n</li>\n<li>The assignment expression <code>y = x = f()</code> has now finished evaluating;\nits result is the new value of <code>y</code> – which happens to be <code>2</code>.\n<code>x</code> and <code>y</code> are assigned to <code>2</code>,\nand the console has printed \"F!\".</li>\n</ol>\n<h4 id=\"evaluation_example_2\">Evaluation example 2</h4>\n<p><code>y = [ f(), x = g() ]</code> also evaluates from left to right:</p>\n<ol>\n<li>The assignment expression <code>y = [ f(), x = g() ]</code> starts to evaluate.\n<ol>\n<li>The <code>y</code> on this assignment's left-hand evaluates\ninto a reference to the variable named <code>y</code>.</li>\n<li>The inner array literal <code>[ f(), x = g() ]</code> starts to evaluate.\n<ol>\n<li>The function call <code>f()</code> prints \"F!\" to the console and\nthen evaluates to the number <code>2</code>.</li>\n<li>The assignment expression <code>x = g()</code> starts to evaluate.\n<ol>\n<li>The <code>x</code> on this assignment's left-hand side evaluates\ninto a reference to the variable named <code>x</code>.</li>\n<li>The function call <code>g()</code> prints \"G!\" to the console and\nthen evaluates to the number <code>3</code>.</li>\n<li>That <code>3</code> result from <code>g()</code> is assigned to <code>x</code>.</li>\n</ol>\n</li>\n<li>The assignment expression <code>x = g()</code> has now finished evaluating;\nits result is the new value of <code>x</code>, which is <code>3</code>.\nThat <code>3</code> result becomes the next element\nin the inner array literal (after the <code>2</code> from the <code>f()</code>).</li>\n</ol>\n</li>\n<li>The inner array literal <code>[ f(), x = g() ]</code>\nhas now finished evaluating;\nits result is an array with two values: <code>[ 2, 3 ]</code>.</li>\n<li>That <code>[ 2, 3 ]</code> array is now assigned to <code>y</code>.</li>\n</ol>\n</li>\n<li>The assignment expression <code>y = [ f(), x = g() ]</code> has\nnow finished evaluating;\nits result is the new value of <code>y</code> – which happens to be <code>[ 2, 3 ]</code>.\n<code>x</code> is now assigned to <code>3</code>,\n<code>y</code> is now assigned to <code>[ 2, 3 ]</code>,\nand the console has printed \"F!\" then \"G!\".</li>\n</ol>\n<h4 id=\"evaluation_example_3\">Evaluation example 3</h4>\n<p><code>x[f()] = g()</code> also evaluates from left to right.\n(This example assumes that <code>x</code> is already assigned to some object.\nFor more information about objects, read <a href=\"/en-US/docs/Web/JavaScript/Guide/Working_with_objects\">Working with Objects</a>.)</p>\n<ol>\n<li>The assignment expression <code>x[f()] = g()</code> starts to evaluate.\n<ol>\n<li>The <code>x[f()]</code> property access on this assignment's left-hand\nstarts to evaluate.\n<ol>\n<li>The <code>x</code> in this property access evaluates\ninto a reference to the variable named <code>x</code>.</li>\n<li>Then the function call <code>f()</code> prints \"F!\" to the console and\nthen evaluates to the number <code>2</code>.</li>\n</ol>\n</li>\n<li>The <code>x[f()]</code> property access on this assignment\nhas now finished evaluating;\nits result is a variable property reference: <code>x[2]</code>.</li>\n<li>Then the function call <code>g()</code> prints \"G!\" to the console and\nthen evaluates to the number <code>3</code>.</li>\n<li>That <code>3</code> is now assigned to <code>x[2]</code>.\n(This step will succeed only if <code>x</code> is assigned to an <a href=\"/en-US/docs/Web/JavaScript/Guide/Working_with_objects\">object</a>.)</li>\n</ol>\n</li>\n<li>The assignment expression <code>x[f()] = g()</code> has now finished evaluating;\nits result is the new value of <code>x[2]</code> – which happens to be <code>3</code>.\n<code>x[2]</code> is now assigned to <code>3</code>,\nand the console has printed \"F!\" then \"G!\".</li>\n</ol>"}},{"type":"prose","value":{"id":"avoid_assignment_chains","title":"Avoid assignment chains","isH3":true,"content":"<p>Chaining assignments or nesting assignments in other expressions can\nresult in surprising behavior. For this reason,\n<a href=\"https://github.com/airbnb/javascript/blob/master/README.md#variables--no-chain-assignment\" class=\"external\" target=\"_blank\">chaining assignments in the same statement is discouraged</a>.</p>\n<p>In particular, putting a variable chain in a <a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/const\"><code>const</code></a>, <a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/let\"><code>let</code></a>, or <a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/var\"><code>var</code></a> statement often does <em>not</em> work. Only the outermost/leftmost variable would get declared; other variables within the assignment chain are <em>not</em> declared by the <code>const</code>/<code>let</code>/<code>var</code> statement.\nFor example:</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>const z = y = x = f();\n</code></pre></div>\n<p>This statement seemingly declares the variables <code>x</code>, <code>y</code>, and <code>z</code>.\nHowever, it only actually declares the variable <code>z</code>.\n<code>y</code> and <code>x</code> are either invalid references to nonexistent variables (in <a href=\"/en-US/docs/Web/JavaScript/Reference/Strict_mode\">strict mode</a>) or, worse, would implicitly create <a href=\"/en-US/docs/Glossary/Global_variable\">global variables</a> for <code>x</code> and <code>y</code> in <a href=\"/en-US/docs/Glossary/Sloppy_mode\">sloppy mode</a>.</p>"}},{"type":"prose","value":{"id":"comparison_operators","title":"Comparison operators","isH3":false,"content":"<p>A comparison operator compares its operands and returns a logical value based on whether the comparison is true.\nThe operands can be numerical, string, logical, or <a href=\"/en-US/docs/Web/JavaScript/Guide/Working_with_objects\">object</a> values.\nStrings are compared based on standard lexicographical ordering, using Unicode values.\nIn most cases, if the two operands are not of the same type, JavaScript attempts to convert them to an appropriate type for the comparison.\nThis behavior generally results in comparing the operands numerically.\nThe sole exceptions to type conversion within comparisons involve the <code>===</code> and <code>!==</code> operators, which perform strict equality and inequality comparisons.\nThese operators do not attempt to convert the operands to compatible types before checking equality.\nThe following table describes the comparison operators in terms of this sample code:</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>const var1 = 3;\nconst var2 = 4;\n</code></pre></div>\n<figure class=\"table-container\"><table class=\"standard-table\">\n <caption>\n Comparison operators\n </caption>\n <thead>\n <tr>\n <th scope=\"col\">Operator</th>\n <th scope=\"col\">Description</th>\n <th scope=\"col\">Examples returning true</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <td>\n <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Equality\">Equal</a> (<code>==</code>)\n </td>\n <td>Returns <code>true</code> if the operands are equal.</td>\n <td>\n <code>3 == var1</code>\n <p><code>\"3\" == var1</code></p>\n <code>3 == '3'</code>\n </td>\n </tr>\n <tr>\n <td>\n <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Inequality\">Not equal</a> (<code>!=</code>)\n </td>\n <td>Returns <code>true</code> if the operands are not equal.</td>\n <td>\n <code>var1 != 4<br>var2 != \"3\"</code>\n </td>\n </tr>\n <tr>\n <td>\n <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality\">Strict equal</a> (<code>===</code>)\n </td>\n <td>\n Returns <code>true</code> if the operands are equal and of the same\n type. See also <a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is\"><code>Object.is</code></a> and\n <a href=\"/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness\">sameness in JS</a>.\n </td>\n <td><code>3 === var1</code></td>\n </tr>\n <tr>\n <td>\n <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Strict_inequality\">Strict not equal</a> (<code>!==</code>)\n </td>\n <td>\n Returns <code>true</code> if the operands are of the same type but not equal, or are of different type.\n </td>\n <td>\n <code>var1 !== \"3\"<br>3 !== '3'</code>\n </td>\n </tr>\n <tr>\n <td>\n <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Greater_than\">Greater than</a> (<code>&gt;</code>)\n </td>\n <td>\n Returns <code>true</code> if the left operand is greater than the right operand.\n </td>\n <td>\n <code>var2 &gt; var1<br>\"12\" &gt; 2</code>\n </td>\n </tr>\n <tr>\n <td>\n <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Greater_than_or_equal\">Greater than or equal</a>\n (<code>&gt;=</code>)\n </td>\n <td>\n Returns <code>true</code> if the left operand is greater than or equal to the right operand.\n </td>\n <td>\n <code>var2 &gt;= var1<br>var1 &gt;= 3</code>\n </td>\n </tr>\n <tr>\n <td>\n <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Less_than\">Less than</a>\n (<code>&lt;</code>)\n </td>\n <td>\n Returns <code>true</code> if the left operand is less than the right operand.\n </td>\n <td>\n <code>var1 &lt; var2<br>\"2\" &lt; 12</code>\n </td>\n </tr>\n <tr>\n <td>\n <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Less_than_or_equal\">Less than or equal</a>\n (<code>&lt;=</code>)\n </td>\n <td>\n Returns <code>true</code> if the left operand is less than or equal to the right operand.\n </td>\n <td>\n <code>var1 &lt;= var2<br>var2 &lt;= 5</code>\n </td>\n </tr>\n </tbody>\n</table></figure>\n<div class=\"notecard note\">\n<p><strong>Note:</strong> <code>=&gt;</code> is not a comparison operator but rather is the notation\nfor <a href=\"/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions\">Arrow functions</a>.</p>\n</div>"}},{"type":"prose","value":{"id":"arithmetic_operators","title":"Arithmetic operators","isH3":false,"content":"<p>An arithmetic operator takes numerical values (either literals or variables) as their operands and returns a single numerical value.\nThe standard arithmetic operators are addition (<code>+</code>), subtraction (<code>-</code>), multiplication (<code>*</code>), and division (<code>/</code>).\nThese operators work as they do in most other programming languages when used with floating point numbers (in particular, note that division by zero produces <a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Infinity\"><code>Infinity</code></a>). For example:</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>1 / 2; // 0.5\n1 / 2 === 1.0 / 2.0; // this is true\n</code></pre></div>\n<p>In addition to the standard arithmetic operations (<code>+</code>, <code>-</code>, <code>*</code>, <code>/</code>), JavaScript provides the arithmetic operators listed in the following table:</p>\n<figure class=\"table-container\"><table class=\"fullwidth-table\">\n <caption>\n Arithmetic operators\n </caption>\n <thead>\n <tr>\n <th scope=\"col\">Operator</th>\n <th scope=\"col\">Description</th>\n <th scope=\"col\">Example</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <td>\n <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Remainder\">Remainder</a> (<code>%</code>)\n </td>\n <td>\n Binary operator. Returns the integer remainder of dividing the two operands.\n </td>\n <td>12 % 5 returns 2.</td>\n </tr>\n <tr>\n <td>\n <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Increment\">Increment</a> (<code>++</code>)\n </td>\n <td>\n Unary operator. Adds one to its operand. If used as a prefix operator\n (<code>++x</code>), returns the value of its operand after adding one;\n if used as a postfix operator (<code>x++</code>), returns the value of\n its operand before adding one.\n </td>\n <td>\n If <code>x</code> is 3, then <code>++x</code> sets <code>x</code> to 4\n and returns 4, whereas <code>x++</code> returns 3 and, only then, sets <code>x</code> to 4.\n </td>\n </tr>\n <tr>\n <td>\n <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Decrement\">Decrement</a> (<code>--</code>)\n </td>\n <td>\n Unary operator. Subtracts one from its operand.\n The return value is analogous to that for the increment operator.\n </td>\n <td>\n If <code>x</code> is 3, then <code>--x</code> sets <code>x</code> to 2\n and returns 2, whereas <code>x--</code> returns 3 and, only then, sets <code>x</code> to 2.\n </td>\n </tr>\n <tr>\n <td>\n <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Unary_negation\">Unary negation</a> (<code>-</code>)\n </td>\n <td>Unary operator. Returns the negation of its operand.</td>\n <td>If <code>x</code> is 3, then <code>-x</code> returns -3.</td>\n </tr>\n <tr>\n <td>\n <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Unary_plus\">Unary plus</a> (<code>+</code>)\n </td>\n <td>\n Unary operator. Attempts to <a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number#number_coercion\">convert the operand to a number</a>, if it is not already.\n </td>\n <td>\n <p><code>+\"3\"</code> returns <code>3</code>.</p>\n <p><code>+true</code> returns <code>1</code>.</p>\n </td>\n </tr>\n <tr>\n <td>\n <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation\">Exponentiation operator</a> (<code>**</code>)\n </td>\n <td>\n Calculates the <code>base</code> to the <code>exponent</code> power,\n that is, <code>base^exponent</code>\n </td>\n <td>\n <code>2 ** 3</code> returns <code>8</code>.<br><code>10 ** -1</code>\n returns <code>0.1</code>.\n </td>\n </tr>\n </tbody>\n</table></figure>"}},{"type":"prose","value":{"id":"bitwise_operators","title":"Bitwise operators","isH3":false,"content":"<p>A bitwise operator treats their operands as a set of 32 bits (zeros and ones), rather\nthan as decimal, hexadecimal, or octal numbers. For example, the decimal number nine has\na binary representation of 1001. Bitwise operators perform their operations on such\nbinary representations, but they return standard JavaScript numerical values.</p>\n<p>The following table summarizes JavaScript's bitwise operators.</p>\n<figure class=\"table-container\"><table>\n<thead>\n<tr>\n<th>Operator</th>\n<th>Usage</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_AND\">Bitwise AND</a></td>\n<td><code>a &amp; b</code></td>\n<td>Returns a one in each bit position for which the corresponding bits of both operands are ones.</td>\n</tr>\n<tr>\n<td><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_OR\">Bitwise OR</a></td>\n<td><code>a | b</code></td>\n<td>Returns a zero in each bit position for which the corresponding bits of both operands are zeros.</td>\n</tr>\n<tr>\n<td><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_XOR\">Bitwise XOR</a></td>\n<td><code>a ^ b</code></td>\n<td>Returns a zero in each bit position for which the corresponding bits are the same. [Returns a one in each bit position for which the corresponding bits are different.]</td>\n</tr>\n<tr>\n<td><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_NOT\">Bitwise NOT</a></td>\n<td><code>~ a</code></td>\n<td>Inverts the bits of its operand.</td>\n</tr>\n<tr>\n<td><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Left_shift\">Left shift</a></td>\n<td><code>a &lt;&lt; b</code></td>\n<td>Shifts <code>a</code> in binary representation <code>b</code> bits to the left, shifting in zeros from the right.</td>\n</tr>\n<tr>\n<td><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Right_shift\">Sign-propagating right shift</a></td>\n<td><code>a &gt;&gt; b</code></td>\n<td>Shifts <code>a</code> in binary representation <code>b</code> bits to the right, discarding bits shifted off.</td>\n</tr>\n<tr>\n<td><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Unsigned_right_shift\">Zero-fill right shift</a></td>\n<td><code>a &gt;&gt;&gt; b</code></td>\n<td>Shifts <code>a</code> in binary representation <code>b</code> bits to the right, discarding bits shifted off, and shifting in zeros from the left.</td>\n</tr>\n</tbody>\n</table></figure>"}},{"type":"prose","value":{"id":"bitwise_logical_operators","title":"Bitwise logical operators","isH3":true,"content":"<p>Conceptually, the bitwise logical operators work as follows:</p>\n<ul>\n<li>\n<p>The operands are converted to thirty-two-bit integers and expressed by a series of bits (zeros and ones).\nNumbers with more than 32 bits get their most significant bits discarded.\nFor example, the following integer with more than 32 bits will be converted to a 32-bit integer:</p>\n<pre class=\"brush: plain notranslate\">Before: 1110 0110 1111 1010 0000 0000 0000 0110 0000 0000 0001\nAfter: 1010 0000 0000 0000 0110 0000 0000 0001\n</pre>\n</li>\n<li>\n<p>Each bit in the first operand is paired with the corresponding bit in the second operand: first bit to first bit, second bit to second bit, and so on.</p>\n</li>\n<li>\n<p>The operator is applied to each pair of bits, and the result is constructed bitwise.</p>\n</li>\n</ul>\n<p>For example, the binary representation of nine is 1001, and the binary representation of fifteen is 1111.\nSo, when the bitwise operators are applied to these values, the results are as follows:</p>\n<figure class=\"table-container\"><table>\n<thead>\n<tr>\n<th>Expression</th>\n<th>Result</th>\n<th>Binary Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>15 &amp; 9</code></td>\n<td><code>9</code></td>\n<td><code>1111 &amp; 1001 = 1001</code></td>\n</tr>\n<tr>\n<td><code>15 | 9</code></td>\n<td><code>15</code></td>\n<td><code>1111 | 1001 = 1111</code></td>\n</tr>\n<tr>\n<td><code>15 ^ 9</code></td>\n<td><code>6</code></td>\n<td><code>1111 ^ 1001 = 0110</code></td>\n</tr>\n<tr>\n<td><code>~15</code></td>\n<td><code>-16</code></td>\n<td><code>~ 0000 0000 … 0000 1111 = 1111 1111 … 1111 0000</code></td>\n</tr>\n<tr>\n<td><code>~9</code></td>\n<td><code>-10</code></td>\n<td><code>~ 0000 0000 … 0000 1001 = 1111 1111 … 1111 0110</code></td>\n</tr>\n</tbody>\n</table></figure>\n<p>Note that all 32 bits are inverted using the Bitwise NOT operator, and that values with\nthe most significant (left-most) bit set to 1 represent negative numbers\n(two's-complement representation). <code>~x</code> evaluates to the same value that\n<code>-x - 1</code> evaluates to.</p>"}},{"type":"prose","value":{"id":"bitwise_shift_operators","title":"Bitwise shift operators","isH3":true,"content":"<p>The bitwise shift operators take two operands: the first is a quantity to be shifted, and the second specifies the number of bit positions by which the first operand is to be\nshifted.\nThe direction of the shift operation is controlled by the operator used.</p>\n<p>Shift operators convert their operands to thirty-two-bit integers and return a result of either type <a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number\"><code>Number</code></a> or <a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt\"><code>BigInt</code></a>: specifically, if the type\nof the left operand is <a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt\"><code>BigInt</code></a>, they return <a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt\"><code>BigInt</code></a>;\notherwise, they return <a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number\"><code>Number</code></a>.</p>\n<p>The shift operators are listed in the following table.</p>\n<figure class=\"table-container\"><table class=\"fullwidth-table\">\n <caption>\n Bitwise shift operators\n </caption>\n <thead>\n <tr>\n <th scope=\"col\">Operator</th>\n <th scope=\"col\">Description</th>\n <th scope=\"col\">Example</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <td>\n <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Left_shift\">Left shift</a><br>(<code>&lt;&lt;</code>)\n </td>\n <td>\n This operator shifts the first operand the specified number of bits to\n the left. Excess bits shifted off to the left are discarded. Zero bits\n are shifted in from the right.\n </td>\n <td>\n <code>9&lt;&lt;2</code> yields 36, because 1001 shifted 2 bits to\n the left becomes 100100, which is 36.\n </td>\n </tr>\n <tr>\n <td>\n <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Right_shift\">Sign-propagating right shift</a> (<code>&gt;&gt;</code>)\n </td>\n <td>\n This operator shifts the first operand the specified number of bits to\n the right. Excess bits shifted off to the right are discarded. Copies of\n the leftmost bit are shifted in from the left.\n </td>\n <td>\n <code>9&gt;&gt;2</code> yields 2, because 1001 shifted 2 bits to the right\n becomes 10, which is 2. Likewise, <code>-9&gt;&gt;2</code> yields -3, because the sign is preserved.\n </td>\n </tr>\n <tr>\n <td>\n <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Unsigned_right_shift\">Zero-fill right shift</a> (<code>&gt;&gt;&gt;</code>)\n </td>\n <td>\n This operator shifts the first operand the specified number of bits to\n the right. Excess bits shifted off to the right are discarded. Zero bits\n are shifted in from the left.\n </td>\n <td>\n <code>19&gt;&gt;&gt;2</code> yields 4, because 10011 shifted 2 bits to the right\n becomes 100, which is 4. For non-negative numbers, zero-fill right shift\n and sign-propagating right shift yield the same result.\n </td>\n </tr>\n </tbody>\n</table></figure>"}},{"type":"prose","value":{"id":"logical_operators","title":"Logical operators","isH3":false,"content":"<p>Logical operators are typically used with Boolean (logical) values; when they are, they return a Boolean value.\nHowever, the <code>&amp;&amp;</code>, <code>||</code>, and <code>??</code> operators actually return the value of one of the specified operands, so if these\noperators are used with non-Boolean values, they may return a non-Boolean value. As such, they are more adequately called \"value selection operators\".\nThe logical operators are described in the following table.</p>\n<figure class=\"table-container\"><table class=\"fullwidth-table\">\n <caption>\n Logical operators\n </caption>\n <thead>\n <tr>\n <th scope=\"col\">Operator</th>\n <th scope=\"col\">Usage</th>\n <th scope=\"col\">Description</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <td>\n <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Logical_AND\">Logical AND</a> (<code>&amp;&amp;</code>)\n </td>\n <td><code>expr1 &amp;&amp; expr2</code></td>\n <td>\n Returns <code>expr1</code> if it can be converted to <code>false</code>;\n otherwise, returns <code>expr2</code>. Thus, when used with Boolean\n values, <code>&amp;&amp;</code> returns <code>true</code> if both\n operands are true; otherwise, returns <code>false</code>.\n </td>\n </tr>\n <tr>\n <td>\n <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR\">Logical OR</a> (<code>||</code>)\n </td>\n <td><code>expr1 || expr2</code></td>\n <td>\n Returns <code>expr1</code> if it can be converted to <code>true</code>;\n otherwise, returns <code>expr2</code>. Thus, when used with Boolean\n values, <code>||</code> returns <code>true</code> if either operand is\n true; if both are false, returns <code>false</code>.\n </td>\n </tr>\n <tr>\n <td>\n <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing\">Nullish coalescing operator</a> (<code>??</code>)\n </td>\n <td><code>expr1 ?? expr2</code></td>\n <td>\n Returns <code>expr1</code> if it is neither <code>null</code> nor\n <code>undefined</code>; otherwise, returns <code>expr2</code>.\n </td>\n </tr>\n <tr>\n <td>\n <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Logical_NOT\">Logical NOT</a> (<code>!</code>)\n </td>\n <td><code>!expr</code></td>\n <td>\n Returns <code>false</code> if its single operand can be converted\n to <code>true</code>; otherwise, returns <code>true</code>.\n </td>\n </tr>\n </tbody>\n</table></figure>\n<p>Examples of expressions that can be converted to <code>false</code> are those that evaluate to <code>null</code>, <code>0</code>, <code>0n</code>, <code>NaN</code>, the empty string (<code>\"\"</code>), or <code>undefined</code>.</p>\n<p>The following code shows examples of the <code>&amp;&amp;</code> (logical AND) operator.</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>const a1 = true &amp;&amp; true; // t &amp;&amp; t returns true\nconst a2 = true &amp;&amp; false; // t &amp;&amp; f returns false\nconst a3 = false &amp;&amp; true; // f &amp;&amp; t returns false\nconst a4 = false &amp;&amp; 3 === 4; // f &amp;&amp; f returns false\nconst a5 = \"Cat\" &amp;&amp; \"Dog\"; // t &amp;&amp; t returns Dog\nconst a6 = false &amp;&amp; \"Cat\"; // f &amp;&amp; t returns false\nconst a7 = \"Cat\" &amp;&amp; false; // t &amp;&amp; f returns false\n</code></pre></div>\n<p>The following code shows examples of the <code>||</code> (logical OR) operator.</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>const o1 = true || true; // t || t returns true\nconst o2 = false || true; // f || t returns true\nconst o3 = true || false; // t || f returns true\nconst o4 = false || 3 === 4; // f || f returns false\nconst o5 = \"Cat\" || \"Dog\"; // t || t returns Cat\nconst o6 = false || \"Cat\"; // f || t returns Cat\nconst o7 = \"Cat\" || false; // t || f returns Cat\n</code></pre></div>\n<p>The following code shows examples of the <code>??</code> (nullish coalescing) operator.</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>const n1 = null ?? 1; // 1\nconst n2 = undefined ?? 2; // 2\nconst n3 = false ?? 3; // false\nconst n4 = 0 ?? 4; // 0\n</code></pre></div>\n<p>Note how <code>??</code> works like <code>||</code>, but it only returns the second expression when the first one is \"<a href=\"/en-US/docs/Glossary/Nullish\">nullish</a>\", i.e. <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/null\"><code>null</code></a> or <a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined\"><code>undefined</code></a>. <code>??</code> is a better alternative than <code>||</code> for setting defaults for values that might be <code>null</code> or <code>undefined</code>, in particular when values like <code>''</code> or <code>0</code> are valid values and the default should not apply.</p>\n<p>The following code shows examples of the <code>!</code> (logical NOT) operator.</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>const n1 = !true; // !t returns false\nconst n2 = !false; // !f returns true\nconst n3 = !\"Cat\"; // !t returns false\n</code></pre></div>"}},{"type":"prose","value":{"id":"short-circuit_evaluation","title":"Short-circuit evaluation","isH3":true,"content":"<p>As logical expressions are evaluated left to right, they are tested for possible\n\"short-circuit\" evaluation using the following rules:</p>\n<ul>\n<li><code>falsy &amp;&amp; anything</code> is short-circuit evaluated to the falsy value.</li>\n<li><code>truthy || anything</code> is short-circuit evaluated to the truthy value.</li>\n<li><code>nonNullish ?? anything</code> is short-circuit evaluated to the non-nullish value.</li>\n</ul>\n<p>The rules of logic guarantee that these evaluations are always correct. Note that the\n<em>anything</em> part of the above expressions is not evaluated, so any side effects of\ndoing so do not take effect.</p>"}},{"type":"prose","value":{"id":"bigint_operators","title":"BigInt operators","isH3":false,"content":"<p>Most operators that can be used between numbers can be used between <a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt\"><code>BigInt</code></a> values as well.</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>// BigInt addition\nconst a = 1n + 2n; // 3n\n// Division with BigInts round towards zero\nconst b = 1n / 2n; // 0n\n// Bitwise operations with BigInts do not truncate either side\nconst c = 40000000000000000n &gt;&gt; 2n; // 10000000000000000n\n</code></pre></div>\n<p>One exception is <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Unsigned_right_shift\">unsigned right shift (<code>&gt;&gt;&gt;</code>)</a>, which is not defined for BigInt values. This is because a BigInt does not have a fixed width, so technically it does not have a \"highest bit\".</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>const d = 8n &gt;&gt;&gt; 2n; // TypeError: BigInts have no unsigned right shift, use &gt;&gt; instead\n</code></pre></div>\n<p>BigInts and numbers are not mutually replaceable — you cannot mix them in calculations.</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js example-bad notranslate\"><code>const a = 1n + 2; // TypeError: Cannot mix BigInt and other types\n</code></pre></div>\n<p>This is because BigInt is neither a subset nor a superset of numbers. BigInts have higher precision than numbers when representing large integers, but cannot represent decimals, so implicit conversion on either side might lose precision. Use explicit conversion to signal whether you wish the operation to be a number operation or a BigInt one.</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js example-good notranslate\"><code>const a = Number(1n) + 2; // 3\nconst b = 1n + BigInt(2); // 3n\n</code></pre></div>\n<p>You can compare BigInts with numbers.</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>const a = 1n &gt; 2; // false\nconst b = 3 &gt; 2n; // true\n</code></pre></div>"}},{"type":"prose","value":{"id":"string_operators","title":"String operators","isH3":false,"content":"<p>In addition to the comparison operators, which can be used on string values, the concatenation operator (+) concatenates two string values together, returning another string that is the union of the two operand strings.</p>\n<p>For example,</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>console.log(\"my \" + \"string\"); // console logs the string \"my string\".\n</code></pre></div>\n<p>The shorthand assignment operator <code>+=</code> can also be used to concatenate strings.</p>\n<p>For example,</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>let myString = \"alpha\";\nmyString += \"bet\"; // evaluates to \"alphabet\" and assigns this value to myString.\n</code></pre></div>"}},{"type":"prose","value":{"id":"conditional_ternary_operator","title":"Conditional (ternary) operator","isH3":false,"content":"<p>The <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_operator\">conditional operator</a>\nis the only JavaScript operator that takes three operands.\nThe operator can have one of two values based on a condition.\nThe syntax is:</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>condition ? val1 : val2\n</code></pre></div>\n<p>If <code>condition</code> is true, the operator has the value of <code>val1</code>.\nOtherwise it has the value of <code>val2</code>. You can use the conditional operator anywhere you would use a standard operator.</p>\n<p>For example,</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>const status = age &gt;= 18 ? \"adult\" : \"minor\";\n</code></pre></div>\n<p>This statement assigns the value \"adult\" to the variable <code>status</code> if\n<code>age</code> is eighteen or more. Otherwise, it assigns the value \"minor\" to\n<code>status</code>.</p>"}},{"type":"prose","value":{"id":"comma_operator","title":"Comma operator","isH3":false,"content":"<p>The <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Comma_operator\">comma operator</a> (<code>,</code>)\nevaluates both of its operands and returns the value of the last operand.\nThis operator is primarily used inside a <code>for</code> loop, to allow multiple variables to be updated each time through the loop.\nIt is regarded bad style to use it elsewhere, when it is not necessary.\nOften two separate statements can and should be used instead.</p>\n<p>For example, if <code>a</code> is a 2-dimensional array with 10 elements on a side, the following code uses the comma operator to update two variables at once.\nThe code prints the values of the diagonal elements in the array:</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>const x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];\nconst a = [x, x, x, x, x];\n\nfor (let i = 0, j = 9; i &lt;= j; i++, j--) {\n // ^\n console.log(`a[${i}][${j}]= ${a[i][j]}`);\n}\n</code></pre></div>"}},{"type":"prose","value":{"id":"unary_operators","title":"Unary operators","isH3":false,"content":"<p>A unary operation is an operation with only one operand.</p>"}},{"type":"prose","value":{"id":"delete","title":"delete","isH3":true,"content":"<p>The <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/delete\"><code>delete</code></a> operator deletes an object's property.\nThe syntax is:</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>delete object.property;\ndelete object[propertyKey];\ndelete objectName[index];\n</code></pre></div>\n<p>where <code>object</code> is the name of an object, <code>property</code> is an existing property, and <code>propertyKey</code> is a string or symbol referring to an existing property.</p>\n<p>If the <code>delete</code> operator succeeds, it removes the property from the object.\nTrying to access it afterwards will yield <code>undefined</code>.\nThe <code>delete</code> operator returns <code>true</code> if the operation is possible; it returns <code>false</code> if the operation is not possible.</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>delete Math.PI; // returns false (cannot delete non-configurable properties)\n\nconst myObj = { h: 4 };\ndelete myObj.h; // returns true (can delete user-defined properties)\n</code></pre></div>\n<h4 id=\"deleting_array_elements\">Deleting array elements</h4>\n<p>Since arrays are just objects, it's technically possible to <code>delete</code> elements from them.\nThis is, however, regarded as a bad practice — try to avoid it.\nWhen you delete an array property, the array length is not affected and other elements are not re-indexed.\nTo achieve that behavior, it is much better to just overwrite the element with the value <code>undefined</code>.\nTo actually manipulate the array, use the various array methods such as <a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice\"><code>splice</code></a>.</p>"}},{"type":"prose","value":{"id":"typeof","title":"typeof","isH3":true,"content":"<p>The <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/typeof\"><code>typeof</code> operator</a> returns a string indicating the type of the unevaluated operand.\n<code>operand</code> is the string, variable, keyword, or object for which the type is to be returned.\nThe parentheses are optional.</p>\n<p>Suppose you define the following variables:</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>const myFun = new Function(\"5 + 2\");\nconst shape = \"round\";\nconst size = 1;\nconst foo = [\"Apple\", \"Mango\", \"Orange\"];\nconst today = new Date();\n</code></pre></div>\n<p>The <code>typeof</code> operator returns the following results for these variables:</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>typeof myFun; // returns \"function\"\ntypeof shape; // returns \"string\"\ntypeof size; // returns \"number\"\ntypeof foo; // returns \"object\"\ntypeof today; // returns \"object\"\ntypeof doesntExist; // returns \"undefined\"\n</code></pre></div>\n<p>For the keywords <code>true</code> and <code>null</code>, the <code>typeof</code>\noperator returns the following results:</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>typeof true; // returns \"boolean\"\ntypeof null; // returns \"object\"\n</code></pre></div>\n<p>For a number or string, the <code>typeof</code> operator returns the following results:</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>typeof 62; // returns \"number\"\ntypeof \"Hello world\"; // returns \"string\"\n</code></pre></div>\n<p>For property values, the <code>typeof</code> operator returns the type of value the\nproperty contains:</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>typeof document.lastModified; // returns \"string\"\ntypeof window.length; // returns \"number\"\ntypeof Math.LN2; // returns \"number\"\n</code></pre></div>\n<p>For methods and functions, the <code>typeof</code> operator returns results as follows:</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>typeof blur; // returns \"function\"\ntypeof eval; // returns \"function\"\ntypeof parseInt; // returns \"function\"\ntypeof shape.split; // returns \"function\"\n</code></pre></div>\n<p>For predefined objects, the <code>typeof</code> operator returns results as follows:</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>typeof Date; // returns \"function\"\ntypeof Function; // returns \"function\"\ntypeof Math; // returns \"object\"\ntypeof Option; // returns \"function\"\ntypeof String; // returns \"function\"\n</code></pre></div>"}},{"type":"prose","value":{"id":"void","title":"void","isH3":true,"content":"<p>The <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/void\"><code>void</code> operator</a> specifies an expression to be evaluated without returning a value. <code>expression</code> is a JavaScript expression to evaluate.\nThe parentheses surrounding the expression are optional, but it is good style to use them to avoid precedence issues.</p>"}},{"type":"prose","value":{"id":"relational_operators","title":"Relational operators","isH3":false,"content":"<p>A relational operator compares its operands and returns a Boolean value based on whether the comparison is true.</p>"}},{"type":"prose","value":{"id":"in","title":"in","isH3":true,"content":"<p>The <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/in\"><code>in</code> operator</a> returns <code>true</code> if the specified property is in the specified object.\nThe syntax is:</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>propNameOrNumber in objectName\n</code></pre></div>\n<p>where <code>propNameOrNumber</code> is a string, numeric, or symbol expression representing a property name or array index, and <code>objectName</code> is the name of an object.</p>\n<p>The following examples show some uses of the <code>in</code> operator.</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>// Arrays\nconst trees = [\"redwood\", \"bay\", \"cedar\", \"oak\", \"maple\"];\n0 in trees; // returns true\n3 in trees; // returns true\n6 in trees; // returns false\n\"bay\" in trees; // returns false\n// (you must specify the index number, not the value at that index)\n\"length\" in trees; // returns true (length is an Array property)\n\n// built-in objects\n\"PI\" in Math; // returns true\nconst myString = new String(\"coral\");\n\"length\" in myString; // returns true\n\n// Custom objects\nconst myCar = { make: \"Honda\", model: \"Accord\", year: 1998 };\n\"make\" in myCar; // returns true\n\"model\" in myCar; // returns true\n</code></pre></div>"}},{"type":"prose","value":{"id":"instanceof","title":"instanceof","isH3":true,"content":"<p>The <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/instanceof\"><code>instanceof</code> operator</a> returns <code>true</code>\nif the specified object is of the specified object type. The syntax is:</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>object instanceof objectType\n</code></pre></div>\n<p>where <code>object</code> is the object to test against <code>objectType</code>, and <code>objectType</code> is a constructor representing a type, such as <a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map\"><code>Map</code></a> or <a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array\"><code>Array</code></a>.</p>\n<p>Use <code>instanceof</code> when you need to confirm the type of an object at runtime.\nFor example, when catching exceptions, you can branch to different exception-handling code depending on the type of exception thrown.</p>\n<p>For example, the following code uses <code>instanceof</code> to determine whether <code>obj</code> is a <code>Map</code> object. Because <code>obj</code> is a <code>Map</code> object, the statements inside the <code>if</code> block execute.</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>const obj = new Map();\nif (obj instanceof Map) {\n // statements to execute\n}\n</code></pre></div>"}},{"type":"prose","value":{"id":"basic_expressions","title":"Basic expressions","isH3":false,"content":"<p>All operators eventually operate on one or more basic expressions. These basic expressions include <a href=\"/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#declarations\">identifiers</a> and <a href=\"/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#literals\">literals</a>, but there are a few other kinds as well. They are briefly introduced below, and their semantics are described in detail in their respective reference sections.</p>"}},{"type":"prose","value":{"id":"this","title":"this","isH3":true,"content":"<p>Use the <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/this\"><code>this</code> keyword</a> to refer to the current object.\nIn general, <code>this</code> refers to the calling object in a method.\nUse <code>this</code> either with the dot or the bracket notation:</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>this[\"propertyName\"];\nthis.propertyName;\n</code></pre></div>\n<p>Suppose a function called <code>validate</code> validates an object's <code>value</code> property, given the object and the high and low values:</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>function validate(obj, lowVal, highVal) {\n if (obj.value &lt; lowVal || obj.value &gt; highVal) {\n console.log(\"Invalid Value!\");\n }\n}\n</code></pre></div>\n<p>You could call <code>validate</code> in each form element's <code>onChange</code> event handler, using <code>this</code> to pass it to the form element, as in the following example:</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">html</span></div><pre class=\"brush: html notranslate\"><code>&lt;p&gt;Enter a number between 18 and 99:&lt;/p&gt;\n&lt;input type=\"text\" name=\"age\" size=\"3\" onChange=\"validate(this, 18, 99);\" /&gt;\n</code></pre></div>"}},{"type":"prose","value":{"id":"grouping_operator","title":"Grouping operator","isH3":true,"content":"<p>The grouping operator <code>( )</code> controls the precedence of evaluation in\nexpressions. For example, you can override multiplication and division first, then\naddition and subtraction to evaluate addition first.</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>const a = 1;\nconst b = 2;\nconst c = 3;\n\n// default precedence\na + b * c // 7\n// evaluated by default like this\na + (b * c) // 7\n\n// now overriding precedence\n// addition before multiplication\n(a + b) * c // 9\n\n// which is equivalent to\na * c + b * c // 9\n</code></pre></div>"}},{"type":"prose","value":{"id":"property_accessor","title":"Property accessor","isH3":true,"content":"<p>The <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors\">property accessor</a> syntax gets property values on objects, using either dot notation or bracket notation.</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>object.property;\nobject[\"property\"];\n</code></pre></div>\n<p>The <a href=\"/en-US/docs/Web/JavaScript/Guide/Working_with_objects\">working with objects</a> guide goes into more details about object properties.</p>"}},{"type":"prose","value":{"id":"optional_chaining","title":"Optional chaining","isH3":true,"content":"<p>The <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining\">optional chaining</a> syntax (<code>?.</code>) performs the chained operation on an object if it is defined and non-<code>null</code>, and otherwise short-circuits the operation and returns <code>undefined</code>.\nThis allows you to operate on a value that may be <code>null</code> or <code>undefined</code> without causing a <code>TypeError</code>.</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>maybeObject?.property;\nmaybeObject?.[property];\nmaybeFunction?.();\n</code></pre></div>"}},{"type":"prose","value":{"id":"new","title":"new","isH3":true,"content":"<p>You can use the <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/new\"><code>new</code> operator</a> to create an instance of a user-defined object type or of one of the built-in object types. Use <code>new</code> as follows:</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>const objectName = new ObjectType(param1, param2, /* …, */ paramN);\n</code></pre></div>"}},{"type":"prose","value":{"id":"super","title":"super","isH3":true,"content":"<p>The <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/super\"><code>super</code> keyword</a> is used to call functions on an object's parent.\nIt is useful with <a href=\"/en-US/docs/Web/JavaScript/Reference/Classes\">classes</a> to call the parent constructor, for example.</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>super(args); // calls the parent constructor.\nsuper.functionOnParent(args);\n</code></pre></div>\n<ul class=\"prev-next\"><li><a class=\"button secondary\" href=\"/en-US/docs/Web/JavaScript/Guide/Functions\"><span class=\"button-wrap\"> Previous </span></a></li><li><a class=\"button secondary\" href=\"/en-US/docs/Web/JavaScript/Guide/Numbers_and_strings\"><span class=\"button-wrap\"> Next </span></a></li></ul>"}}],"isActive":true,"isMarkdown":true,"isTranslated":false,"locale":"en-US","mdn_url":"/en-US/docs/Web/JavaScript/Guide/Expressions_and_operators","modified":"2025-01-20T22:28:20.000Z","native":"English (US)","noIndexing":false,"other_translations":[{"locale":"de","title":"Ausdrücke und Operatoren","native":"Deutsch"},{"locale":"es","title":"Expresiones y operadores","native":"Español"},{"locale":"fr","title":"Expressions et opérateurs","native":"Français"},{"locale":"ja","title":"式と演算子","native":"日本語"},{"locale":"ko","title":"표현식과 연산자","native":"한국어"},{"locale":"pt-BR","title":"Expressões e operadores","native":"Português (do Brasil)"},{"locale":"ru","title":"Выражения и операторы","native":"Русский"},{"locale":"zh-CN","title":"表达式与运算符","native":"中文 (简体)"},{"locale":"zh-TW","title":"運算式與運算子","native":"正體中文 (繁體)"}],"pageTitle":"Expressions and operators - JavaScript | MDN","parents":[{"uri":"/en-US/docs/Web","title":"References"},{"uri":"/en-US/docs/Web/JavaScript","title":"JavaScript"},{"uri":"/en-US/docs/Web/JavaScript/Guide","title":"Guide"},{"uri":"/en-US/docs/Web/JavaScript/Guide/Expressions_and_operators","title":"Expressions and operators"}],"popularity":null,"short_title":"Expressions and operators","sidebarHTML":"<ol><li class=\"section\"><a href=\"/en-US/docs/Web/JavaScript\">JavaScript</a></li><li class=\"section\">Tutorials and guides</li><li class=\"toggle\"><details><summary>Beginner's tutorials</summary><ol><li><a href=\"/en-US/docs/Learn_web_development/Getting_started/Your_first_website/Adding_interactivity\">Your first website: Adding interactivity</a></li><li><a href=\"/en-US/docs/Learn_web_development/Core/Scripting\">Dynamic scripting with JavaScript</a></li><li><a href=\"/en-US/docs/Learn_web_development/Core/Frameworks_libraries\">JavaScript frameworks and libraries</a></li></ol></details></li><li class=\"toggle\"><details open=\"\"><summary>JavaScript Guide</summary><ol><li><a href=\"/en-US/docs/Web/JavaScript/Guide/Introduction\">Introduction</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Guide/Grammar_and_types\">Grammar and types</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Guide/Control_flow_and_error_handling\">Control flow and error handling</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration\">Loops and iteration</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Guide/Functions\">Functions</a></li><li><em><a href=\"/en-US/docs/Web/JavaScript/Guide/Expressions_and_operators\" aria-current=\"page\">Expressions and operators</a></em></li><li><a href=\"/en-US/docs/Web/JavaScript/Guide/Numbers_and_strings\">Numbers and strings</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Guide/Representing_dates_times\">Representing dates &amp; times</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Guide/Regular_expressions\">Regular expressions</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Guide/Indexed_collections\">Indexed collections</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Guide/Keyed_collections\">Keyed collections</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Guide/Working_with_objects\">Working with objects</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Guide/Using_classes\">Using classes</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Guide/Using_promises\">Using promises</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Guide/Typed_arrays\">JavaScript typed arrays</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Guide/Iterators_and_generators\">Iterators and generators</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Guide/Internationalization\">Internationalization</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Guide/Meta_programming\">Meta programming</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Guide/Modules\">JavaScript modules</a></li></ol></details></li><li class=\"toggle\"><details><summary>Intermediate</summary><ol><li><a href=\"/en-US/docs/Learn_web_development/Extensions/Advanced_JavaScript_objects\">Advanced JavaScript objects</a></li><li><a href=\"/en-US/docs/Learn_web_development/Extensions/Async_JS\">Asynchronous JavaScript</a></li><li><a href=\"/en-US/docs/Learn_web_development/Extensions/Client-side_APIs\">Client-side web APIs</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Language_overview\">Language overview</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Data_structures\">JavaScript data structures</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness\">Equality comparisons and sameness</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties\">Enumerability and ownership of properties</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Closures\">Closures</a></li></ol></details></li><li class=\"toggle\"><details><summary>Advanced</summary><ol><li><a href=\"/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain\">Inheritance and the prototype chain</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Memory_management\">Memory Management</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Event_loop\">Concurrency model and Event Loop</a></li></ol></details></li><li class=\"section\"><a href=\"/en-US/docs/Web/JavaScript/Reference\">References</a></li><li class=\"toggle\"><details><summary>Built-in objects</summary><ol><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects\">Overview</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError\">AggregateError</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array\">Array</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer\">ArrayBuffer</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncFunction\">AsyncFunction</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator\">AsyncGenerator</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGeneratorFunction\">AsyncGeneratorFunction</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncIterator\">AsyncIterator</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics\">Atomics</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt\">BigInt</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array\">BigInt64Array</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array\">BigUint64Array</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean\">Boolean</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView\">DataView</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date\">Date</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURI\">decodeURI()</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent\">decodeURIComponent()</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI\">encodeURI()</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent\">encodeURIComponent()</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error\">Error</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape\">escape()</a><abbr class=\"icon icon-deprecated\" title=\"Deprecated. Not for use in new websites.\">\n<span class=\"visually-hidden\">Deprecated</span>\n</abbr></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval\">eval()</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError\">EvalError</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry\">FinalizationRegistry</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array\">Float16Array</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array\">Float32Array</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array\">Float64Array</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function\">Function</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator\">Generator</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/GeneratorFunction\">GeneratorFunction</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis\">globalThis</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Infinity\">Infinity</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array\">Int16Array</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array\">Int32Array</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array\">Int8Array</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/InternalError\">InternalError</a><abbr class=\"icon icon-nonstandard\" title=\"Non-standard. Check cross-browser support before using.\">\n<span class=\"visually-hidden\">Non-standard</span>\n</abbr></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl\">Intl</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite\">isFinite()</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN\">isNaN()</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator\">Iterator</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON\">JSON</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map\">Map</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math\">Math</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN\">NaN</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number\">Number</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\">Object</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat\">parseFloat()</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt\">parseInt()</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise\">Promise</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy\">Proxy</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError\">RangeError</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError\">ReferenceError</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect\">Reflect</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp\">RegExp</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set\">Set</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer\">SharedArrayBuffer</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/String\">String</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol\">Symbol</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError\">SyntaxError</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal\">Temporal</a><abbr class=\"icon icon-experimental\" title=\"Experimental. Expect behavior to change in the future.\">\n<span class=\"visually-hidden\">Experimental</span>\n</abbr></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray\">TypedArray</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError\">TypeError</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array\">Uint16Array</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array\">Uint32Array</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array\">Uint8Array</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray\">Uint8ClampedArray</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined\">undefined</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/unescape\">unescape()</a><abbr class=\"icon icon-deprecated\" title=\"Deprecated. Not for use in new websites.\">\n<span class=\"visually-hidden\">Deprecated</span>\n</abbr></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError\">URIError</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap\">WeakMap</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef\">WeakRef</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet\">WeakSet</a></li></ol></details></li><li class=\"toggle\"><details><summary>Expressions &amp; operators</summary><ol><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators\">Overview</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Addition\">Addition (+)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Addition_assignment\">Addition assignment (+=)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Assignment\">Assignment (=)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/async_function\">async function expression</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/async_function*\">async function* expression</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/await\">await</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_AND\">Bitwise AND (&amp;)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_AND_assignment\">Bitwise AND assignment (&amp;=)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_NOT\">Bitwise NOT (~)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_OR\">Bitwise OR (|)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_OR_assignment\">Bitwise OR assignment (|=)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_XOR\">Bitwise XOR (^)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_XOR_assignment\">Bitwise XOR assignment (^=)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/class\">class expression</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Comma_operator\">Comma operator (,)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_operator\">Conditional (ternary) operator</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Decrement\">Decrement (--)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/delete\">delete</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment\">Destructuring assignment</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Division\">Division (/)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Division_assignment\">Division assignment (/=)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Equality\">Equality (==)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation\">Exponentiation (**)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation_assignment\">Exponentiation assignment (**=)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/function\">function expression</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/function*\">function* expression</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Greater_than\">Greater than (&gt;)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Greater_than_or_equal\">Greater than or equal (&gt;=)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Grouping\">Grouping operator ( )</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/import.meta\">import.meta</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/import\">import()</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/in\">in</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Increment\">Increment (++)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Inequality\">Inequality (!=)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/instanceof\">instanceof</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Left_shift\">Left shift (&lt;&lt;)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Left_shift_assignment\">Left shift assignment (&lt;&lt;=)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Less_than\">Less than (&lt;)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Less_than_or_equal\">Less than or equal (&lt;=)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Logical_AND\">Logical AND (&amp;&amp;)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Logical_AND_assignment\">Logical AND assignment (&amp;&amp;=)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Logical_NOT\">Logical NOT (!)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR\">Logical OR (||)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR_assignment\">Logical OR assignment (||=)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Multiplication\">Multiplication (*)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Multiplication_assignment\">Multiplication assignment (*=)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/new\">new</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/new.target\">new.target</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/null\">null</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_assignment\">Nullish coalescing assignment (??=)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing\">Nullish coalescing operator (??)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer\">Object initializer</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Operator_precedence\">Operator precedence</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining\">Optional chaining (?.)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors\">Property accessors</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Remainder\">Remainder (%)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Remainder_assignment\">Remainder assignment (%=)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Right_shift\">Right shift (&gt;&gt;)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Right_shift_assignment\">Right shift assignment (&gt;&gt;=)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax\">Spread syntax (...)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality\">Strict equality (===)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Strict_inequality\">Strict inequality (!==)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Subtraction\">Subtraction (-)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Subtraction_assignment\">Subtraction assignment (-=)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/super\">super</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/this\">this</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/typeof\">typeof</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Unary_negation\">Unary negation (-)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Unary_plus\">Unary plus (+)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Unsigned_right_shift\">Unsigned right shift (&gt;&gt;&gt;)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/Unsigned_right_shift_assignment\">Unsigned right shift assignment (&gt;&gt;&gt;=)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/void\">void operator</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/yield\">yield</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/yield*\">yield*</a></li></ol></details></li><li class=\"toggle\"><details><summary>Statements &amp; declarations</summary><ol><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Statements\">Overview</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/async_function\">async function</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/async_function*\">async function*</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/block\">Block statement</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/break\">break</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/class\">class</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/const\">const</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/continue\">continue</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/debugger\">debugger</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/do...while\">do...while</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/Empty\">Empty statement</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/export\">export</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/Expression_statement\">Expression statement</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/for\">for</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\">for await...of</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/for...in\">for...in</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/for...of\">for...of</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/function\">function</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/function*\">function*</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/if...else\">if...else</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/import\">import</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/label\">Labeled statement</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/let\">let</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/return\">return</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/switch\">switch</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/throw\">throw</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/try...catch\">try...catch</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/var\">var</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/while\">while</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/with\">with</a><abbr class=\"icon icon-deprecated\" title=\"Deprecated. Not for use in new websites.\">\n<span class=\"visually-hidden\">Deprecated</span>\n</abbr></li></ol></details></li><li class=\"toggle\"><details><summary>Functions</summary><ol><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Functions\">Overview</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions\">Arrow function expressions</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters\">Default parameters</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Functions/get\">get</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Functions/Method_definitions\">Method definitions</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters\">Rest parameters</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Functions/set\">set</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Functions/arguments\">The arguments object</a></li></ol></details></li><li class=\"toggle\"><details><summary>Classes</summary><ol><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Classes\">Overview</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Classes/constructor\">constructor</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Classes/extends\">extends</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Classes/Private_properties\">Private properties</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Classes/Public_class_fields\">Public class fields</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Classes/static\">static</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Classes/Static_initialization_blocks\">Static initialization blocks</a></li></ol></details></li><li class=\"toggle\"><details><summary>Regular expressions</summary><ol><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Regular_expressions\">Overview</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Backreference\">Backreference: \\1, \\2</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Capturing_group\">Capturing group: (...)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Character_class_escape\">Character class escape: \\d, \\D, \\w, \\W, \\s, \\S</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Character_class\">Character class: [...], [^...]</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Character_escape\">Character escape: \\n, \\u{...}</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Disjunction\">Disjunction: |</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Input_boundary_assertion\">Input boundary assertion: ^, $</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Literal_character\">Literal character: a, b</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Lookahead_assertion\">Lookahead assertion: (?=...), (?!...)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Lookbehind_assertion\">Lookbehind assertion: (?&lt;=...), (?&lt;!...)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Modifier\">Modifier: (?ims-ims:...)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Named_backreference\">Named backreference: \\k&lt;name&gt;</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Named_capturing_group\">Named capturing group: (?&lt;name&gt;...)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Non-capturing_group\">Non-capturing group: (?:...)</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Quantifier\">Quantifier: *, +, ?, {n}, {n,}, {n,m}</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Unicode_character_class_escape\">Unicode character class escape: \\p{...}, \\P{...}</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Wildcard\">Wildcard: .</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Word_boundary_assertion\">Word boundary assertion: \\b, \\B</a></li></ol></details></li><li class=\"toggle\"><details><summary>Errors</summary><ol><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors\">Overview</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Promise_any_all_rejected\">AggregateError: No Promise in Promise.any was resolved</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Property_access_denied\">Error: Permission denied to access property \"x\"</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Too_much_recursion\">InternalError: too much recursion</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Not_a_valid_code_point\">RangeError: argument is not a valid code point</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/BigInt_division_by_zero\">RangeError: BigInt division by zero</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/BigInt_negative_exponent\">RangeError: BigInt negative exponent</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Form_must_be_one_of\">RangeError: form must be one of 'NFC', 'NFD', 'NFKC', or 'NFKD'</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_array_length\">RangeError: invalid array length</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_date\">RangeError: invalid date</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Precision_range\">RangeError: precision is out of range</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Bad_radix\">RangeError: radix must be an integer</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Resulting_string_too_large\">RangeError: repeat count must be less than infinity</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Negative_repetition_count\">RangeError: repeat count must be non-negative</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Cant_be_converted_to_BigInt_because_it_isnt_an_integer\">RangeError: x can't be converted to BigInt because it isn't an integer</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Not_defined\">ReferenceError: \"x\" is not defined</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Undeclared_var\">ReferenceError: assignment to undeclared variable \"x\"</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Cant_access_lexical_declaration_before_init\">ReferenceError: can't access lexical declaration 'X' before initialization</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Deprecated_caller_or_arguments_usage\">ReferenceError: deprecated caller or arguments usage</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Super_not_called\">ReferenceError: must call super constructor before using 'this' in derived class constructor</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Super_called_twice\">ReferenceError: super() called twice in derived class constructor</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Bad_strict_arguments_eval\">SyntaxError: 'arguments'/'eval' can't be defined or assigned to in strict mode code</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Deprecated_octal_literal\">SyntaxError: \"0\"-prefixed octal literals are deprecated</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Strict_non_simple_params\">SyntaxError: \"use strict\" not allowed in function with non-simple parameters</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Reserved_identifier\">SyntaxError: \"x\" is a reserved identifier</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Regex_backslash_at_end_of_pattern\">SyntaxError: \\ at end of pattern</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_for-of_initializer\">SyntaxError: a declaration in the head of a for-of loop can't have an initializer</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Delete_in_strict_mode\">SyntaxError: applying the 'delete' operator to an unqualified name is deprecated</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Arguments_not_allowed\">SyntaxError: arguments is not valid in fields</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Bad_await\">SyntaxError: await is only valid in async functions, async generators and modules</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/await_yield_in_parameter\">SyntaxError: await/yield expression can't be used in parameter</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Cant_use_nullish_coalescing_unparenthesized\">SyntaxError: cannot use `??` unparenthesized within `||` and `&amp;&amp;` expressions</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Regex_character_class_escape_in_class_range\">SyntaxError: character class escape cannot be used in class range in regular expression</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Bad_continue\">SyntaxError: continue must be inside loop</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Regex_duplicate_capture_group_name\">SyntaxError: duplicate capture group name in regular expression</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Duplicate_parameter\">SyntaxError: duplicate formal argument x</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_for-in_initializer\">SyntaxError: for-in loop head declarations may not have initializers</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Unnamed_function_statement\">SyntaxError: function statement requires a name</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Function_label\">SyntaxError: functions cannot be labelled</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Either_be_both_static_or_non-static\">SyntaxError: getter and setter for private name #x should either be both static or non-static</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Getter_no_arguments\">SyntaxError: getter functions must have no arguments</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Identifier_after_number\">SyntaxError: identifier starts immediately after numeric literal</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Illegal_character\">SyntaxError: illegal character</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/import_decl_module_top_level\">SyntaxError: import declarations may only appear at top level of a module</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Regex_incomplete_quantifier\">SyntaxError: incomplete quantifier in regular expression</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_assignment_left-hand_side\">SyntaxError: invalid assignment left-hand side</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_BigInt_syntax\">SyntaxError: invalid BigInt syntax</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Regex_invalid_capture_group_name\">SyntaxError: invalid capture group name in regular expression</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Regex_invalid_char_in_class\">SyntaxError: invalid character in class in regular expression</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Regex_invalid_class_set_operation\">SyntaxError: invalid class set operation in regular expression</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Regex_invalid_decimal_escape\">SyntaxError: invalid decimal escape in regular expression</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Regex_invalid_identity_escape\">SyntaxError: invalid identity escape in regular expression</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Regex_invalid_named_capture_reference\">SyntaxError: invalid named capture reference in regular expression</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Regex_invalid_property_name\">SyntaxError: invalid property name in regular expression</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Regex_invalid_range_in_character_class\">SyntaxError: invalid range in character class</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Regex_invalid_group\">SyntaxError: invalid regexp group</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Bad_regexp_flag\">SyntaxError: invalid regular expression flag \"x\"</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Regex_invalid_unicode_escape\">SyntaxError: invalid unicode escape in regular expression</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/JSON_bad_parse\">SyntaxError: JSON.parse: bad parsing</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Label_not_found\">SyntaxError: label not found</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Missing_colon_after_property_id\">SyntaxError: missing : after property id</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Missing_parenthesis_after_argument_list\">SyntaxError: missing ) after argument list</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Missing_parenthesis_after_condition\">SyntaxError: missing ) after condition</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Missing_bracket_after_list\">SyntaxError: missing ] after element list</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Missing_curly_after_function_body\">SyntaxError: missing } after function body</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Missing_curly_after_property_list\">SyntaxError: missing } after property list</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Missing_initializer_in_const\">SyntaxError: missing = in const declaration</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Missing_formal_parameter\">SyntaxError: missing formal parameter</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Missing_name_after_dot_operator\">SyntaxError: missing name after . operator</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/No_variable_name\">SyntaxError: missing variable name</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Regex_negated_char_class_with_strings\">SyntaxError: negated character class with strings in regular expression</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Bad_new_optional\">SyntaxError: new keyword cannot be used with an optional chain</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Regex_nothing_to_repeat\">SyntaxError: nothing to repeat</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Regex_numbers_out_of_order_in_quantifier\">SyntaxError: numbers out of order in {} quantifier.</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Deprecated_octal_escape_sequence\">SyntaxError: octal escape sequences can't be used in untagged template literals or in strict mode code</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Parameter_after_rest_parameter\">SyntaxError: parameter after rest parameter</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Cant_delete_private_fields\">SyntaxError: private fields can't be deleted</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Duplicate_proto\">SyntaxError: property name __proto__ appears more than once in object literal</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Regex_raw_bracket\">SyntaxError: raw bracket is not allowed in regular expression with unicode flag</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Redeclared_parameter\">SyntaxError: redeclaration of formal parameter \"x\"</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Undeclared_private_field_or_method\">SyntaxError: reference to undeclared private field or method #x</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Rest_with_default\">SyntaxError: rest parameter may not have a default</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Bad_return\">SyntaxError: return not in function</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Setter_one_argument\">SyntaxError: setter functions must have one argument</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/String_literal_EOL\">SyntaxError: string literal contains an unescaped line break</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Bad_super_call\">SyntaxError: super() is only valid in derived class constructors</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Bad_optional_template\">SyntaxError: tagged template cannot be used with optional chain</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Hash_outside_class\">SyntaxError: Unexpected '#' used outside of class body</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Unexpected_token\">SyntaxError: Unexpected token</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Bad_break\">SyntaxError: unlabeled break must be inside loop or switch</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Unparenthesized_unary_expr_lhs_exponentiation\">SyntaxError: unparenthesized unary expression can't appear on the left-hand side of '**'</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Bad_super_prop\">SyntaxError: use of super property/member accesses only valid within methods or eval code within methods</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Deprecated_source_map_pragma\">SyntaxError: Using //@ to indicate sourceURL pragmas is deprecated. Use //# instead</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/is_not_iterable\">TypeError: 'x' is not iterable</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Unexpected_type\">TypeError: \"x\" is (not) \"y\"</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Not_a_constructor\">TypeError: \"x\" is not a constructor</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Not_a_function\">TypeError: \"x\" is not a function</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/No_non-null_object\">TypeError: \"x\" is not a non-null object</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Read-only\">TypeError: \"x\" is read-only</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/BigInt_not_serializable\">TypeError: BigInt value can't be serialized in JSON</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Builtin_ctor_no_new\">TypeError: calling a builtin X constructor without new is forbidden</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Get_set_missing_private\">TypeError: can't access/set private field or method: object is not the right class</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Cant_assign_to_property\">TypeError: can't assign to property \"x\" on \"y\": not an object</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Cant_convert_BigInt_to_number\">TypeError: can't convert BigInt to number</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Cant_convert_x_to_BigInt\">TypeError: can't convert x to BigInt</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Cant_define_property_object_not_extensible\">TypeError: can't define property \"x\": \"obj\" is not extensible</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Non_configurable_array_element\">TypeError: can't delete non-configurable array element</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Cant_redefine_property\">TypeError: can't redefine non-configurable property \"x\"</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Cant_set_prototype\">TypeError: can't set prototype of this object</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_prototype\">TypeError: can't set prototype: it would cause a prototype chain cycle</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/in_operator_no_object\">TypeError: cannot use 'in' operator to search for 'x' in 'y'</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Class_ctor_no_new\">TypeError: class constructors must be invoked with 'new'</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value\">TypeError: cyclic object value</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_derived_return\">TypeError: derived class constructor returned invalid value x</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Private_setter_only\">TypeError: getting private setter-only property</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Private_double_initialization\">TypeError: Initializing an object twice is an error with private fields/methods</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/invalid_right_hand_side_instanceof_operand\">TypeError: invalid 'instanceof' operand 'x'</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Array_sort_argument\">TypeError: invalid Array.prototype.sort argument</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_const_assignment\">TypeError: invalid assignment to const \"x\"</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Constructor_cant_be_used_directly\">TypeError: Iterator/AsyncIterator constructor can't be used directly</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Requires_global_RegExp\">TypeError: matchAll/replaceAll must be called with a global RegExp</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/More_arguments_needed\">TypeError: More arguments needed</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/No_properties\">TypeError: null/undefined has no properties</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Cant_delete\">TypeError: property \"x\" is non-configurable and can't be deleted</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Reduce_of_empty_array_with_no_initial_value\">TypeError: Reduce of empty array with no initial value</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Getter_only\">TypeError: setting getter-only property \"x\"</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Key_not_weakly_held\">TypeError: WeakSet key/WeakMap value 'x' must be an object or an unregistered symbol</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Called_on_incompatible_type\">TypeError: X.prototype.y called on incompatible type</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Malformed_URI\">URIError: malformed URI sequence</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Already_has_pragma\">Warning: -file- is being assigned a //# sourceMappingURL, but already has one</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Errors/Stmt_after_return\">Warning: unreachable code after return statement</a></li></ol></details></li><li class=\"toggle\"><details><summary>Misc</summary><ol><li><a href=\"/en-US/docs/Web/JavaScript/JavaScript_technologies_overview\">JavaScript technologies overview</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Lexical_grammar\">Lexical grammar</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Iteration_protocols\">Iteration protocols</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Strict_mode\">Strict mode</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Template_literals\">Template literals</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Trailing_commas\">Trailing commas</a></li><li><a href=\"/en-US/docs/Web/JavaScript/Reference/Deprecated_and_obsolete_features\">Deprecated features</a></li></ol></details></li></ol>","source":{"folder":"en-us/web/javascript/guide/expressions_and_operators","github_url":"https://github.com/mdn/content/blob/main/files/en-us/web/javascript/guide/expressions_and_operators/index.md","last_commit_url":"https://github.com/mdn/content/commit/a4e9bce1e8bac1b845b32536e0e44f335233eab6","filename":"index.md"},"summary":"This chapter describes JavaScript's expressions and operators, including assignment, comparison, arithmetic, bitwise, logical, string, ternary and more.","title":"Expressions and operators","toc":[{"text":"Assignment operators","id":"assignment_operators"},{"text":"Comparison operators","id":"comparison_operators"},{"text":"Arithmetic operators","id":"arithmetic_operators"},{"text":"Bitwise operators","id":"bitwise_operators"},{"text":"Logical operators","id":"logical_operators"},{"text":"BigInt operators","id":"bigint_operators"},{"text":"String operators","id":"string_operators"},{"text":"Conditional (ternary) operator","id":"conditional_ternary_operator"},{"text":"Comma operator","id":"comma_operator"},{"text":"Unary operators","id":"unary_operators"},{"text":"Relational operators","id":"relational_operators"},{"text":"Basic expressions","id":"basic_expressions"}],"pageType":"guide"}}</script></body></html>

Pages: 1 2 3 4 5 6 7 8 9 10