Home > Web Front-end > JS Tutorial > Learn about JS! /+/-/~ function() {/*...*/}() What does it mean?

Learn about JS! /+/-/~ function() {/*...*/}() What does it mean?

coldplay.xixi
Release: 2020-06-29 17:41:59
forward
2730 people have browsed it

Learn about JS! /+/-/~ function() {/*...*/}() What does it mean?

Self-executing anonymous function:

  • Common format: (function() { /* code */ })();
  • Explanation: The first pair of brackets surrounding the function (function(){}) returns an unnamed function to the script, and then a pair of empty brackets immediately executes the returned unnamed function. Inside the brackets are the parameters of the anonymous function.
  • Function: You can use it to create a namespace. As long as you write all your code in this special function package, it will not be accessible from the outside unless you allow it (add window before the variable, so that the function or the variable becomes global). The code of each JavaScript library is basically organized in this form.

To summarize, the main functions of the execution function are anonymous and automatic execution. The code is already running when it is interpreted.

Other writing methods

(function () { /* code */ } ()); 
!function () { /* code */ } ();
~function () { /* code */ } ();
-function () { /* code */ } ();
+function () { /* code */ } ();
Copy after login

Related learning tutorials: javascript tutorial          

The above is the detailed content of Learn about JS! /+/-/~ function() {/*...*/}() What does it mean?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template