Home Web Front-end JS Tutorial Detailed explanation of parameters of javascript function_javascript skills

Detailed explanation of parameters of javascript function_javascript skills

May 16, 2016 pm 03:32 PM
javascript function

Javascript functions can be called with any number of parameters, regardless of how many parameters are specified when the function is defined. Because a function is weakly typed, there is no way to declare the types of arguments it expects, and it is legal to pass any type of value to any function.

1.Js function can pass in different parameters, such as

function writeNString(strMsg){
document.write(strMsg + "<br>");
}
Copy after login

2. Js function returns a value. The js function can return the running result. The function can be regarded as a black box. After inputting data with parameters, the required running result is generated, such as

function one2N(intnumber){
var intTotal = 0;
for(var i=0;i<=intnumber;i++){
 intTotal +=i;}
return intTotal;
}
Copy after login

3. Value-passing and address-passing parameters of Js function

Passing by value: Just pass the value of the variable into the function. The function will allocate additional memory to save the parameter value, so the value of the original variable will not be changed.

Pass address: Pass the memory location where the variable is actually saved into the function, so if the value of the parameter is changed in the function, the value of the original parameter will also be changed at the same time.

Numbers, strings and Boolean---pass by value

Objects, arrays and functions---passing by address

String object————pass address

4. Parameter array of Js function

JS functions all have an Arguments Array object, called arguments object. When calling a function to pass in parameters, even if the function does not specify the parameter name, it can still use the parameter array object to obtain the number of parameters and individual parameter values.

function sumInteger(){
 var total = 0;
 for(var i=0; i<sumInteger.arguments.length;i++){
  total += sumInteger.arguments[i];
  }
  return total;
}
//调用函数
inntotal = sumInteger(100,45,567,234);
document.write("函数sumInteger(100,45,567,234):"+inttotal+"<br>");
Copy after login

5.Variable scope of JS function

JS function has two variables:

Local Variables are variables declared within a function. The variable can only be used within the program line within the function. Program code outside the function cannot access this variable.

Global Variables are variables declared outside the function. This variable can be accessed by the functions and program code of the entire JS program.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Asynchronous Programming of JavaScript Functions: Essential Tips for Handling Complex Tasks Asynchronous Programming of JavaScript Functions: Essential Tips for Handling Complex Tasks Nov 18, 2023 am 10:06 AM

JavaScript Function Asynchronous Programming: Essential Skills for Handling Complex Tasks Introduction: In modern front-end development, handling complex tasks has become an indispensable part. JavaScript function asynchronous programming skills are the key to solving these complex tasks. This article will introduce the basic concepts and common practical methods of JavaScript function asynchronous programming, and provide specific code examples to help readers better understand and use these techniques. 1. Basic concepts of asynchronous programming In traditional synchronous programming, the code is

Use JavaScript functions to implement web page navigation and routing Use JavaScript functions to implement web page navigation and routing Nov 04, 2023 am 09:46 AM

In modern web applications, implementing web page navigation and routing is a very important part. Using JavaScript functions to implement this function can make our web applications more flexible, scalable and user-friendly. This article will introduce how to use JavaScript functions to implement web page navigation and routing, and provide specific code examples. Implementing web page navigation For a web application, web page navigation is the most frequently operated part by users. When a user clicks on the page

Real-time updates to data visualizations using JavaScript functions Real-time updates to data visualizations using JavaScript functions Nov 04, 2023 pm 03:30 PM

Real-time updates of data visualization using JavaScript functions With the development of data science and artificial intelligence, data visualization has become an important data analysis and display tool. By visualizing data, we can understand the relationships and trends between data more intuitively. In web development, JavaScript is a commonly used scripting language with powerful data processing and dynamic interaction functions. This article will introduce how to use JavaScript functions to achieve real-time updates of data visualization, and show the specific

Use JavaScript functions to implement user login and permission verification Use JavaScript functions to implement user login and permission verification Nov 04, 2023 am 10:10 AM

Using JavaScript functions to implement user login and permission verification With the development of the Internet, user login and permission verification have become essential functions for many websites and applications. In order to protect users' data security and access rights, we need to use some technologies and methods to verify the user's identity and restrict their access rights. As a widely used scripting language, JavaScript plays an important role in front-end development. We can use JavaScript functions to implement user login and permission verification functions

Use JavaScript functions to implement image carousels and slideshow effects Use JavaScript functions to implement image carousels and slideshow effects Nov 04, 2023 am 08:59 AM

JavaScript is a scripting language that can be used to add interactive effects to web pages. Among them, image carousel and slideshow effects are common web page animation effects. This article will introduce how to use JavaScript functions to achieve these two effects and provide specific code examples. Picture carousel Picture carousel is an effect that plays multiple pictures in turn in a certain way. When implementing image carousels, JavaScript timers and CSS style controls need to be used. (1) Preparation work First, in the HTML file

Use JavaScript functions to achieve user interaction and dynamic effects Use JavaScript functions to achieve user interaction and dynamic effects Nov 03, 2023 pm 07:02 PM

Using JavaScript functions to achieve user interaction and dynamic effects With the development of modern web design, user interaction and dynamic effects have become the key to attracting users' attention. As a commonly used scripting language, JavaScript has powerful functions and flexible features, and can achieve a variety of user interactions and dynamic effects. This article will introduce some common JavaScript functions and give specific code examples. Changing element style (style) can be easily changed through JavaScript functions

Use JavaScript functions to upload and download files Use JavaScript functions to upload and download files Nov 04, 2023 am 08:30 AM

Using JavaScript functions to implement file upload and download With the development and popularization of the Internet, file upload and download have become one of the common functions in web applications. This article will introduce how to use JavaScript functions to implement file upload and download functions, and provide specific code examples. File upload File upload refers to uploading local files to the server through a web page. FileAPI is provided in HTML5 to handle the selection and upload of files. We can take advantage of Fi in FileAPI

Use JavaScript functions to manipulate DOM elements and modify styles Use JavaScript functions to manipulate DOM elements and modify styles Nov 03, 2023 pm 05:36 PM

Use JavaScript functions to manipulate DOM elements and modify styles JavaScript is a powerful programming language that can be used to manipulate DOM (Document Object Model) elements and modify styles in HTML pages. In this article, we'll learn how to use JavaScript functions to perform these tasks and provide some concrete code examples. Obtaining DOM Elements To operate a DOM element, you first need to find it. We can pass the element using getElementById function

See all articles