js basic entry function
This article introduces you to the basic introductory functions of js. It is more detailed and basic. Friends in need can take a look
1: Function method :
Function: Encapsulate a piece of code! This code implements a certain function. When this function is needed, the function is called.
java:
Modifier return type method name (Data type variable name, multiple) {
Method body;
1.1 The first way to define a function:
js
function function name (parameter list) {
Function body;
}
Function details:
1. The function must be executed after being called.
2. If the function has a return value, you can directly use the data returned by return in the function body. Functions in JS do not have the restriction of return value type.
3. If the function needs to receive parameters, write the variable name directly without the var keyword.4. There is no concept of function overloading in JS. If there are multiple functions with the same name in JS, the previous functions will be overwritten.
5. In JS, if a function needs to accept parameters but does not pass them, then the variables are all undefined
6. Regardless of whether the function in JS accepts parameters or not, when we call it, Parameters can be passed to it.
7. There is a built-in array (arguments) parameter in the function in JS to receive all the data passed. Using arguments, this parameter is actually an array object itself.
Note: If you use a function in JS later and need to accept parameters, define the variables on the function. If not, do not define them. Arguments array operations are rarely used.
<script type="text/javascript"> //定一个函数----求和 //1.在js中,参数列表中,不能书写var 。 如果一个函数需要参数,直接去定义一个参数的名字就可以了 //2.函数,一定要被调用才可以去执行。 调用的方式: 函数名(); //3.如果函数需要返回值,直接在函数中去书写return; //4.在js中没有重载的概念的。如果函数名相同,后面的会把前面的进行覆盖。 /* function sum(a , b ){ alert(a+b); } sum(2,3);//方法不调用,不执行 */ // ====================================================== /* function sum(a , b ){ return a+b; } var s = sum(2,5) ; // 如果需要返回值,就直接return alert(s); */ // ============================================================= function sum(a , b ){ alert(1); return a+b ; } function sum(a , b ,c ){ //js中没有重载的含义,如果方法名相同,那么后面的会把前面的覆盖 alert(2); return a+b ; } var s = sum(2,4);//按java来说两个参数应该会去调两个参数的 alert(s); </script>Copy after login
Bind a method:
1.2 The second definition method of function:
Writing method: var function Name = new Function("Parameter list", "Function body");
The first parameter represents the parameter list
The second parameter represents the function body.
#The function list and parameter body are both defined as strings.
Writing functions are too complicated, so developers rarely use them
1.3 The third way to define a function: anonymous function:
Writing method:
function(参数列表){
函数体;
}
事件:可以理解为一些行为或者动作。如果该行为或者动作有意义,需要我们去做一些事情,此时可以通过事件去调用js中的函数,实现某些功能。
<html> <head> <title>18函数的第三种定义方式.html</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <script type="text/javascript"> /* 1、页面的加载顺序 2、事件: 一个动作或者是一个操作。 3、window.onload === 表示 页面加载完毕 会触发 4、如何为事件去绑定一个函数 对象.事件名=function(){} */ /* // 此时相当于给函数一个名字,demo var demo = function(){ alert("demo"); } //正常的方式函数名()去调用 demo(); */ // window.onload 表示一个事件。 表示当前的页面全部加载完成。 /* 考虑js的执行顺序。或者html的页面的加载顺序。 浏览器加载页面的时候,从上向下,逐步的去加载 */ // 事件: 理解为一件事,或这是一个动作。 例如按钮,点击的时候。 alert("window.onload 之前"); // 函数的第三中定义方式,通常与一个事件进行绑定使用。 window.onload = function(){ alert("demo"); // 1、把按钮的标签获取到 --document.getElementById根据标签的id的属性,获取当前标签 var _button = document.getElementById("b1"); // 对象.事件名 = function(){} _button.onclick = function(){ alert("您点击了按钮"); } } </script> </head> <body> <h1>这是h1</h1> <input type="button" id="b1" value="按钮"> </body> </html>Copy after login1.4全局函数:
js为我们提供了几个全局函数。我们可以直接使用的函数。
url:统一资源定位符
http://www.baidu.com/s/fasdf/basdf
http:// 协议:
www 万维网。 主机名
.baidu.com 域名
/s/fasdf/basdf ---- 资源路径。(资源:互联网中存在的一些文件或者是程序。 例如:html页面。 图片,视频,音频。。。。)
uri:统一资源标识符
/s/fasdf/basdf uri实际上就是一个资源路径。
url 是一种具体的uri 。所以uri的表示范围大于url。(相对来说)
uri 的编码。浏览的地址栏中的内容,会提交到一个服务器。 涉及到http协议 。 不支持中文在url的存在。 需要进行uri的编码。
相关推荐:
The above is the detailed content of js basic entry function. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Kimi: In just one sentence, in just ten seconds, a PPT will be ready. PPT is so annoying! To hold a meeting, you need to have a PPT; to write a weekly report, you need to have a PPT; to make an investment, you need to show a PPT; even when you accuse someone of cheating, you have to send a PPT. College is more like studying a PPT major. You watch PPT in class and do PPT after class. Perhaps, when Dennis Austin invented PPT 37 years ago, he did not expect that one day PPT would become so widespread. Talking about our hard experience of making PPT brings tears to our eyes. "It took three months to make a PPT of more than 20 pages, and I revised it dozens of times. I felt like vomiting when I saw the PPT." "At my peak, I did five PPTs a day, and even my breathing was PPT." If you have an impromptu meeting, you should do it

In the early morning of June 20th, Beijing time, CVPR2024, the top international computer vision conference held in Seattle, officially announced the best paper and other awards. This year, a total of 10 papers won awards, including 2 best papers and 2 best student papers. In addition, there were 2 best paper nominations and 4 best student paper nominations. The top conference in the field of computer vision (CV) is CVPR, which attracts a large number of research institutions and universities every year. According to statistics, a total of 11,532 papers were submitted this year, and 2,719 were accepted, with an acceptance rate of 23.6%. According to Georgia Institute of Technology’s statistical analysis of CVPR2024 data, from the perspective of research topics, the largest number of papers is image and video synthesis and generation (Imageandvideosyn

We know that LLM is trained on large-scale computer clusters using massive data. This site has introduced many methods and technologies used to assist and improve the LLM training process. Today, what we want to share is an article that goes deep into the underlying technology and introduces how to turn a bunch of "bare metals" without even an operating system into a computer cluster for training LLM. This article comes from Imbue, an AI startup that strives to achieve general intelligence by understanding how machines think. Of course, turning a bunch of "bare metal" without an operating system into a computer cluster for training LLM is not an easy process, full of exploration and trial and error, but Imbue finally successfully trained an LLM with 70 billion parameters. and in the process accumulate

Editor of the Machine Power Report: Yang Wen The wave of artificial intelligence represented by large models and AIGC has been quietly changing the way we live and work, but most people still don’t know how to use it. Therefore, we have launched the "AI in Use" column to introduce in detail how to use AI through intuitive, interesting and concise artificial intelligence use cases and stimulate everyone's thinking. We also welcome readers to submit innovative, hands-on use cases. Video link: https://mp.weixin.qq.com/s/2hX_i7li3RqdE4u016yGhQ Recently, the life vlog of a girl living alone became popular on Xiaohongshu. An illustration-style animation, coupled with a few healing words, can be easily picked up in just a few days.

Go language provides two dynamic function creation technologies: closure and reflection. closures allow access to variables within the closure scope, and reflection can create new functions using the FuncOf function. These technologies are useful in customizing HTTP routers, implementing highly customizable systems, and building pluggable components.

In C++ function naming, it is crucial to consider parameter order to improve readability, reduce errors, and facilitate refactoring. Common parameter order conventions include: action-object, object-action, semantic meaning, and standard library compliance. The optimal order depends on the purpose of the function, parameter types, potential confusion, and language conventions.

Retrieval-augmented generation (RAG) is a technique that uses retrieval to boost language models. Specifically, before a language model generates an answer, it retrieves relevant information from an extensive document database and then uses this information to guide the generation process. This technology can greatly improve the accuracy and relevance of content, effectively alleviate the problem of hallucinations, increase the speed of knowledge update, and enhance the traceability of content generation. RAG is undoubtedly one of the most exciting areas of artificial intelligence research. For more details about RAG, please refer to the column article on this site "What are the new developments in RAG, which specializes in making up for the shortcomings of large models?" This review explains it clearly." But RAG is not perfect, and users often encounter some "pain points" when using it. Recently, NVIDIA’s advanced generative AI solution

The key to writing efficient and maintainable Java functions is: keep it simple. Use meaningful naming. Handle special situations. Use appropriate visibility.
