Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the scope of JavaScript local variables and global variables

Shulou Source: shulou.com Published: 2022-06-01 05:16:29 09月10日 Update

In this article Xiaobian for you to introduce in detail "what is the scope of JavaScript local variables and global variables", the content is detailed, the steps are clear, and the details are handled properly. I hope that this article "what is the scope of JavaScript local and global variables" can help you solve your doubts.

Local variable

Variables declared in the body of a function using the var and let keywords are somewhat similar.

Their scope is local:

/ / use var

Function myFunction () {

Var carName = "Volvo"; / / Local scope

}

/ / use let

Function myFunction () {

Let carName = "Volvo"; / / Local scope

}

Global variable

Variables declared outside the function or outside the code block using the var and let keywords are somewhat similar.

Their scope is global:

/ / use var

Var x = 2; / / Global scope

/ / use let

Let x = 2; / / Global scope

Read here, this "what is the scope of JavaScript local variables and global variables" article has been introduced, want to master the knowledge of this article also need to practice and use in order to understand, if you want to know more related articles, welcome to pay attention to the industry information channel.

Tags: Variables functions global local articles keywords contents functions appropriateness code ideas new knowledge more steps knowledge knowledge points articles details industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS OPPO Reno Microsoft MySQL Docker