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

Example Analysis of function default value in ES5 version

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

Share

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

This article mainly introduces the ES5 version of the function default value of the example analysis, the article is very detailed, has a certain reference value, interested friends must read it!

It is common to use a short circuit or operator to set the default value of a function. However, there are some pits. In the code shown below, when the default parameter is a number, the default value will still be used when the parameter is 0. It must be judged separately when y is 0.

Const pow = (x, y) = > {y = y | | 2; let result = 1; for (let I = 0, max = y; I

< max; i++) { result *= x; } return result;}console.log(pow(2)); // =>

4console.log (pow (2,3)); / / > 8max / when the value of y is 0, the value of y is 2console.log (pow (2,0)); / / = > 4 is all the contents of the article "sample Analysis of function default values in ES5 version". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

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