Home > Web Front-end > JS Tutorial > body text

Analysis of the difference between defining variables with var and without var in javascript_javascript skills

WBOY
Release: 2016-05-16 16:20:56
Original
1234 people have browsed it

This article analyzes the difference between defining variables with var and without var in JavaScript. Share it with everyone for your reference. The specific analysis is as follows:

See the instructions directly in the example:

Copy code The code is as follows:

Strictly speaking: the absence of var in the function body does not mean defining a variable, but assigning a variable value, that is, var abc;abc=8. If you assign abc=80 (without var) in the function body, the actual process is like this - the statement first searches for the variable abc in the function body. If it cannot find it, it will continue to search for the variable abc outside the function body. If Still couldn't find it. In the end, I had no choice but to define the variable var abc outside the function body.

So, why

Copy code The code is as follows:
function test(){
abc = 80;
}

This is the reason why variable abc can be called directly outside the function.

I hope this article will be helpful to everyone’s JavaScript programming design.

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!