Js,Javascript加载与函数执行过程

test.html

<!DOCTYPE HTML>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>demo</title>
	<script type="text/javascript">
    	function hello(){
    		alert("hello 1");
    	}
    	hello(); // hello 2
    	function hello(){
    		alert("hello 2");
    	}
    	hello(); // hello 2
    </script>
    <script type="text/javascript">
		hello(); // hello 2
	</script>


    <script type="text/javascript">
    	function hello(){
    		alert("hello 3");
    	}
    	hello(); // hello 4
    	function hello(){
    		alert("hello 4");
    	}
    	hello(); // hello 4
    </script>

    <script type="text/javascript">
		hello(); // hello 4
	</script>
</head>

<script type="text/javascript" src="./test.js"></script>


<script type="text/javascript">
	hello(); // hello js2
</script>
</html>

test.js

function hello(){
	alert("hello js1"); 
}
hello(); // hello js2

function hello(){
	alert("hello js2"); 
}
hello(); // hello js2

小结

1.js中可以允许重复的函数

2.函数式一块一块执行的以script作为块标记

3.同一个块中,如果有同名函数,以后一个为准

4.引入js文件也就是相对于一个大的script块

5.如果在页面底部执行js,相对于以最后一个函数作为执行函数

相关文章:

  • 2022-12-23
  • 2021-10-28
  • 2022-12-23
  • 2021-05-31
  • 2022-12-23
  • 2021-07-19
  • 2021-06-06
猜你喜欢
  • 2021-12-03
  • 2022-12-23
  • 2021-10-27
  • 2021-11-29
  • 2021-10-08
  • 2022-01-18
相关资源
相似解决方案