JS pre-plus semicolon and exclamation point meaning

Source: Internet
Author: User

;!  function () {} (); ;! What's the use?

Go from grammar to open. The semicolon in JavaScript indicates the end of the statement, plus at the beginning. It may be for compression and other methods to cut, indicating a new statement starts. So, let's say it's in a separate JS file. The beginning of the semicolon is no matter what the meaning, can be deleted.

An exclamation point is a logical operator, which is "non", and is commonly written if (!true) {}. Instead of loading the operator in front of the function definition, the function is considered to be a population. Then call this function again. And a logical operation of the returned structure.

Plainly, here is the construction of a running function immediately, it is recommended that the landlord know the meaning can be. When you write, you can use a clearer format:

(function () {}) ();

Add a point here: Add "()" after the function Declaration "functions () {}", meaning to run the function declaration.

Some are called "anonymous self-running functions", more accurately said should be "run function immediately".

But run the function immediately, as part of the expression, or the JS interpreter will report a syntax error. So so. The easiest way to understand an expression is to add a parenthesis to the left and right ends, like this "(function () {})". So, the most common notation for running functions right away is "(function () {})", which is a statement that can be added "in front and behind"; 】。

In fact, running the function immediately also has n notation, such as "(function () {})". Adding a unary operator before a function declaration is also OK: "!function () {} ()", "~function () {} ()".

Even. The combination of unary operators can also: "!!!! function () {} () "," ~~~function () {} () ","!~!function () {} () ").


JS with the meaning of semicolons and exclamation marks

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.