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
Release: 2016-05-16 17:52:20
Original
1092 people have browsed it

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
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