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 write the code of custom function method in javascript

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

Share

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

This article mainly introduces the javascript custom function method code how to write the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this javascript custom function method code how to write the article will have a harvest, let's take a look.

In JavaScript, the code for the custom function method is "function method name (parameter list) {method body}"; the JavaScript function needs to be defined in lowercase function, and "var" is not needed in the parameter list, otherwise an error will be reported.

The operating environment of this tutorial: windows10 system, javascript1.8.5 version, Dell G3 computer.

What is the code for custom function methods in javascript

JS custom functions / methods

A brief description of function and its function

If the code needs to be reused, it can be encapsulated in a function / method for unified writing and use.

Function: enhance the reusability of the code

Format of the function

Function method name (parameter list) {method body}

Note:

Js function definition must use function, and must be lowercase

The js function does not need to define the return type, it can be written directly after function.

There is no need to use the var keyword in the parameter list of JS definition function, otherwise an error will be reported.

Js function weight, return can not be written, can also return specific value, or more recently return can also be

There must be a return value after the function call is executed. The type of the return value is determined according to return. If no specific value is returned in the function, undefined is returned by default.

For example:

Function getSum (aformab) / / Sum:z synthesis; {return aforb;}

There is no function overloading in js. If the function has the same name, only the methods overwrite each other, and the last defined function overrides the previous definition.

Because there is no function overloading in js, the function is called only according to the method name in js, even if the formal parameters of the actual participating function do not match, it will not affect the normal use.

If the parameter is not assigned, it defaults to undefined.

For example:

Function getNum (function getNum b) / / does not need var {return aforb;} function getNum (arecoverbrecc) {return aforbpenc;} alert (getNum (1Power2)); / / the result is NaN, because there is no third parameter value, so a+b+c does not have the correct value. This is the end of the article on "how to write code for custom function methods in javascript". Thank you for reading! I believe that everyone has a certain understanding of "how to write the code of custom function methods in javascript". If you want to learn more, you are 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

  • How to realize the escape of greater than less sign by myBatis

    This article mainly introduces myBatis how to achieve greater than less than sign escape, the article introduces in great detail, has a certain reference value, interested friends must read it! Escape

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

    12
    Report