Home >Web Front-end >JS Tutorial >Analysis of two places where javascript scope is easily misremembered_javascript skills

Analysis of two places where javascript scope is easily misremembered_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:52:201093browse

1.

Copy code The code is as follows:

function fun()
{
var a="rxm";
b="cwr";
}
alert(a);//Error, a local variable
alert(b); //"cwr", bGlobal variables.


2.
Copy code The code is as follows:

var a="rxm";
function fun()
{
alert(a);
var a="123";
alert(a);
}
fun();
alert(a);

Output result: undefined;123;rxm
Statement:
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