Yes, it is a good practice to put all JavaScript declarations at the top. Let's see an example -
<html> <head> <title>JavaScript String match() Method</title> </head> <body> <script> // all the variables declared at top var str, re, found; str = "For more information, see Chapter 3.4.5.1"; re = /(chapter \d+(\.\d)*)/i; found = str.match( re ); document.write(found ); </script> </body> </html>
The following are valid reasons -
The above is the detailed content of In JavaScript, is it a good practice to put all declarations at the top?. For more information, please follow other related articles on the PHP Chinese website!