Home > Web Front-end > JS Tutorial > What is closure in js

What is closure in js

little bottle
Release: 2019-05-31 13:04:30
Original
2664 people have browsed it

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!

Related labels:
js
source:php.cn
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template