Home>Article>Web Front-end> What is closure in js

What is closure in js

little bottle
little bottle Original
2019-05-31 13:04:30 2583browse

In JavaScript, only subfunctions inside a function can read local variables, so closures can be understood as "functions defined inside a function."

What is closure in js

The concept of closure

A closure is a function that can read the internal variables of other functions.

Since in the Javascript language, only sub-functions inside the function can read local variables, closures can be simply understood as "functions defined inside a function".

So, in essence, closure is a bridge connecting the inside of the function with the outside of the function.

Uses of closures

Closures can be used in many places. It has two greatest uses. One is to read the variables inside the function as mentioned earlier, and the other is to keep the values of these variables in memory.

The above is the detailed content of What is closure in js. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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
Previous article:What does js stand for Next article:What does js stand for