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

What is the use of return in javascript

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

Share

Shulou(Shulou.com)05/31 Report--

In this article, the editor introduces in detail "what is the use of return in javascript", the content is detailed, the steps are clear, and the details are handled properly. I hope that this article "what is the use of return in javascript" can help you solve your doubts? let's follow the editor's way of thinking to learn new knowledge.

In javascript, return means "return" and can abort the execution of the current function and return the value of the current function. Once the function has finished executing the return statement, it will immediately return the value of the function and abort the execution of the function. At this time, the code after the return statement will not be executed.

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

Return, which literally means return, the officially defined return statement terminates the current function and returns the value of the current function.

The JavaScript return statement does two things in the function definition:

One is to return the function value.

The second is to abort the execution of the function.

Return statements can return values of any type, including basic data types, objects, functions, and so on. Each function returns a value. When no return statement is used, or when return is used, but no return value is indicated after it, the function returns a "undefined" value. If you need to return a value other than "undefined", you must use return and indicate the returned value.

Once the function has finished executing the return statement, it will immediately return the value of the function and abort the execution of the function. At this time, the code after the return statement will not be executed. According to this characteristic of the return statement, when you need to exit the execution of the function ahead of time, the return statement without return value is often used to abort the execution of the function at any time.

The example 1:return statement explicitly returns the function value

Function expressionCaculate (x) {if ((x > =-10) & & (x b) {console.log ("an is greater than b"); return; console.log ("aqb =" + (aqb));} console.log ("aqb=" + (aqb));} add (7d3)

The add () method is called when the add (7J3) code is executed, where the value of the first parameter is greater than the second parameter, and the output "an is greater than b" in the console, and then the function returns and stops execution, so that neither of the two logs following the return statement is output. The running result is shown in the figure.

After reading this, the article "what is the use of return in javascript" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, 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

Internet Technology

Wechat

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

12
Report