Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the scope type of JavaScript

Shulou Source: shulou.com Published: 2022-06-03 16:31:51 11月14日 Update

This article is to share with you about the scope types of JavaScript. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Description

1. It is divided into global scope and function scope. When accessing variables, the interpreter will first find markers in the current scope.

If you can't find it, go to the parent scope until you find the marker of the variable or it's not in the parent scope.

2. It is worth noting that each subfunction copies the scope of the superior, forming a chain of scope.

Example

Var a = 1 var function F1 () {var a = 2 function f2 () {var a = 3; console.log (a); / / 3}} Thank you for reading! This is the end of this article on "what is the scope type of JavaScript?". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Function type content function variable more tag article good practical superior size global instance article see knowledge interpreter chain reference Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB OPPO Reno NVidia MySQL Microsoft