js comma operator All In One
js comma operator All In One
The comma operator (,) evaluates each of its operands (from left to right) and returns the value of the last operand.
This lets you create a compound expression in which multiple expressions are evaluated, with the compound expression's final value being the value of the rightmost of its member expressions.
This is commonly used to provide multiple parameters to a for loop.
js 逗号运算符
(,) 计算其每个操作数(从左到右
)并返回最后一个操作数
的值
。
这使您可以创建一个复合表达式,在其中计算多个表达式,复合表达式
的最终值是其最右边的成员表达式
的值
。
这通常用于为 for 循环
提供多个参数。
let x = 1;
x = (2, 3, 7);
console.log(x);
// 7
typeof (0, console.log)(`abc`)
// abc
// 'undefined'
typeof (0, console.log)
// 'function'
log = (0, 1, 2, 3, console.log);
// ƒ log() { [native code] }
log(`test`);
// test
// undefined
log = (0, console.log);
// ƒ log() { [native code] }
log(`test`);
// test
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator
demo
(0, console.log)("hello world!")
// hello world!
function test(a, b) {
console.log(`a =`, a);
console.log(`b =`, b);
}
(test)(111, 222)
// a = 111
// b = 222
(0, test)(111, 222)
// a = 111
// b = 222
(1, test)(111, 222)
// a = 111
// b = 222
https://stackoverflow.com/questions/32275135/why-does-babel-rewrite-imported-function-call-to-0-fn
refs
©xgqfrms 2012-2025
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/15948281.html
未经授权禁止转载,违者必究!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
2021-02-28 Apple TV (6th) All In One
2021-02-28 macOS show wifi password All In One
2021-02-28 Apple Store 美国账号注册 All In One
2021-02-28 Apple TV All In One
2021-02-28 Apple 企业采购优惠政策 All In One
2021-02-28 4K 视频 All In One
2020-02-28 SVG 场馆图