What is the scope of JavaScript local variables and global variables
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.