How to declare variables correctly in JavaScript
This article introduces the knowledge of "how to declare variables correctly in JavaScript". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
You cannot use the let keyword to reset variables declared by the var keyword in the same scope or block-level scope:
Var x = 2; / / legal
Let x = 3; / / illegal
{
Var x = 4; / / legal
Let x = 5 / / illegal
}
You cannot use the let keyword to reset variables declared by the let keyword in the same scope or block-level scope:
Let x = 2; / / legal
Let x = 3; / / illegal
{
Let x = 4; / / legal
Let x = 5; / / illegal
}
You cannot use the var keyword to reset variables declared by the let keyword in the same scope or block-level scope:
Let x = 2; / / legal
Var x = 3; / / illegal
{
Let x = 4; / / legal
Var x = 5; / / illegal
}
The let keyword can redeclare assignments in different scopes or in different block-level scopes:
Let x = 2; / / legal
{
Let x = 3; / / legal
}
{
Let x = 4; / / legal
}
This is the end of "how to declare variables correctly in JavaScript". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!