Get the App
SLTechnology News&Howtos  ›  Development  › 

The js function declares how to improve the order

Shulou Source: shulou.com Published: 2022-06-02 23:44:36 11月23日 Update

This article is about how js function declarations improve the order. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

1. First promote the var variable declaration, and then promote the function function declaration.

2. Assuming that the variable name is the same as the function name, the function name identifier that is promoted later will overwrite the variable name that was promoted first. When identifiers are called in subsequent code, the internal process is the definition of the function, not the undefined.

Example

Console.log (a); / /-- > undefinedconsole.log (fun); / /-> fun () {console.log (2);} var a = 1 fun fun = ""; / / there is no declared procedure, only the assignment is "" var (); / / at this time, "" overrides the function and calls not a function. Error function fun () {console.log (2);} Thank you for reading! This is the end of the article on "how to improve the order of js function declarations". I hope the above content can be of some help 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: Functions variables order content more identifiers articles procedures good practical same code only examples articles see knowledge reference help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi OPPO Reno Xiaomi Huawei MariaDB