🔍

首页Home › 开发工具Developer Tools

🧮 编程语言运算符优先级速查表Operator Precedence Table

JavaScript、Python、C、Java、Go、PHP 运算符优先级和结合性对照表:从高到低列出每一级运算符、含义和结合方向,并标注 ?? 混用、-2**2、PHP 8 字符串连接等常见坑。Operator precedence and associativity for JavaScript, Python, C, Java, Go and PHP: every level from highest to lowest with its meaning and direction, plus common gotchas like mixing ??, -2**2 and PHP 8 concatenation.

使用说明与常见问题How-to & FAQ

「编程语言运算符优先级速查表」是什么?What is the Operator Precedence Table tool?

JavaScript、Python、C、Java、Go、PHP 运算符优先级和结合性对照表:从高到低列出每一级运算符、含义和结合方向,并标注 ?? 混用、-2**2、PHP 8 字符串连接等常见坑。Operator precedence and associativity for JavaScript, Python, C, Java, Go and PHP: every level from highest to lowest with its meaning and direction, plus common gotchas like mixing ??, -2**2 and PHP 8 concatenation.

如何使用「编程语言运算符优先级速查表」?How do I use the Operator Precedence Table?

选择语言查看该语言的完整优先级表(序号越小优先级越高),或在搜索框输入运算符(如 ?? 、>>>)跨语言查找。点击运算符可复制。Pick a language to see its full table (lower number = higher precedence), or type an operator such as ?? or >>> to search across languages. Click an operator to copy it.

为什么 JavaScript 中 a ?? b || c 会报错?Why is a ?? b || c a syntax error in JavaScript?

规范禁止 ?? 与 && 或 || 在没有括号的情况下直接混用,以避免优先级歧义。需要写成 (a ?? b) || c 或 a ?? (b || c)。The spec forbids mixing ?? with && or || without parentheses to avoid ambiguity. Write (a ?? b) || c or a ?? (b || c).

Python 里 -2**2 为什么等于 -4?Why is -2**2 equal to -4 in Python?

** 的优先级高于它左侧的一元负号,所以 -2**2 等价于 -(2**2)。如果要计算 (-2) 的平方,请加括号。JavaScript 则直接把 -2**2 判为语法错误。** binds tighter than a unary minus on its left, so -2**2 means -(2**2). Add parentheses for (-2) squared. JavaScript rejects -2**2 as a syntax error.

记不住优先级怎么办?What if I can’t remember the order?

只要表达式混用了不同类别的运算符(位运算与比较、&& 与 ||、三元嵌套等),就加括号。括号不影响性能,还能让代码更易读。Whenever an expression mixes operator kinds (bitwise with comparison, && with ||, nested ternaries), add parentheses. They cost nothing and make code easier to read.

「编程语言运算符优先级速查表」免费吗?数据会上传吗?Is the Operator Precedence Table free? Is my data uploaded?

「编程语言运算符优先级速查表」完全免费,无需注册或安装,手机和电脑都能用;所有处理都在你的浏览器本地完成,输入的内容和文件不会上传到服务器。The Operator Precedence Table is completely free with no sign-up or install and works on phones and desktops; everything runs locally in your browser and nothing you enter is uploaded.

相关工具Related tools

🟨 JS 格式化/压缩JavaScript Beautifier & Minifier🧪 正则表达式测试Regex Tester🧾 JSON 格式化校验JSON Formatter & Validator⚙️ 位运算计算器Bitwise Calculator

← 全部工具All tools