Get the App
SLTechnology News&Howtos  ›  Development  › 

How to declare variables correctly in JavaScript

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

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!

Tags: Legal function key keyword variable same different content more knowledge practical successful next dilemma reality situation article case editor website Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Redmi NVidia MariaDB Docker