xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

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

image

typeof (0, console.log)(`abc`)
// abc
// 'undefined'

typeof (0, console.log)
// 'function'

image

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/62171790/whats-going-on-behind-this-js-function-call-trick-0-console-loghello-worl

https://stackoverflow.com/questions/32275135/why-does-babel-rewrite-imported-function-call-to-0-fn

refs



©xgqfrms 2012-2025

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @   xgqfrms  阅读(38)  评论(2编辑  收藏  举报
相关博文:
阅读排行:
· 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 场馆图
点击右上角即可分享
微信分享提示