Home >Web Front-end >JS Tutorial >Code implementation of js variable promotion
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>
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>
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!