Home > Web Front-end > JS Tutorial > Code implementation of js variable promotion

Code implementation of js variable promotion

不言
Release: 2018-08-23 17:02:01
Original
1792 people have browsed it

The content of this article is about the code implementation of js variable promotion. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Ordinary variable declaration:

<script type="text/javascript">
    alert(a);             //报错  a is not defined
    var a = 1;
</script>
Copy after login

Variable promotion:

<script type="text/javascript">
	alert(a);          //undefined   if语句的变量提升
	if(1<2){
	    var a = 1;
	}
	box();
        function box(){
	    alert(b);      //undefined   函数的变量提升
	    if(1<2){
		var b = 2;
	    }
	}
</script>
Copy after login

Related recommendations:


The above is the detailed content of Code implementation of js variable promotion. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template