Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the JavaScript comma operator

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to use the JavaScript comma operator, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!

Comma operator

I was surprised when I realized that the comma (,) was a separate operator and I had never noticed it before. I've used a lot of commas in my code, but I've never realized its other uses.

Operator is used to calculate each of its operands from left to right and returns the value of the last Operand.

Let count = 1 ret = (count++, count); console.log (ret); copy code

In the above example, the value of the variable ret will be 2. Similarly, the following code records the output value of 32 in the console to the console.

Let val = (12,32); console.log (val)

Where do we use it? Any ideas? The most common use of the comma (,) operator is to provide multiple parameters in a for loop.

For (var I = 0, j = 50; I

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report