<html>
<body>
<script type="text/javascript">
var amt=100;
function a(){
var amt =amt;
alert(amt)
}
a()
</script>
</body>
</html>
<html>
<body>
<script type="text/javascript">
var amt=100;
function a(){
var amt =amt;
alert(amt)
}
a()
</script>
</body>
</html>
function a(){
// var amt = amt;
var amt;
amt = amt;
`undefined`
}
the so-called declaration advance can be understood as engine pre-scan code, putting all variables declared by var at the top of the scope
function a(){
var amt = undefined;
amt = amt;
alert(amt)
}
the amt accessed at this time is naturally undefined.
-Magic dividing line-
positive solution:
`amt`
`var amt = amt` => `var amt; amt = amt`
`amt` `amt` `amt`
the original answer is wrong:
amt
-Magic dividing line-
Tip: please put the main body of the answer in the answer, not in the comment
Edit By: moon Lord LM
declaration has been promoted. It gives priority to the
scope of the internal variable, brother. The internal scope of the function cannot access the external amt variable
. Although the answer that has been adopted is correct, it does not explain the specific principle.
or the 2nd floor chenqiao is to the point. That is, the var declaration will execute
first in the domain, even if you get the variables of the outfield above the declaration, for example:
function a () {
console.log (amt) / / in the order of execution, Li should execute this
var amt = amt; / / but because there is a statement here, this is the first
console.log (amt);
}
so that the execution steps eventually become:
function a () {
var amt;
amt = amt;
console.log (amt);
console.log (amt);
}
I look at a html ui project with items such as: var apiserver = window[ apiserver ]; url = apiserver + "filterUrlController getUrlData"; I searched the whole project and couldn t find the value of window [ apiserver ]. How do you un...
this is the appearance that will occur when the facebook hypothetical state does not appear, and will not disappear until the content is released, and the content will be displayed. How do you do that? And he will buy it, not just a piece of film. It...
under the guidance of others, modified the problem, before sent the wrong question and did not express clearly, the code is as follows. The left side of the colon can be written like this [ result$ {I} AV ]. The number is obtained by the index, but the ...
var url = x.php ; var get = add_x ; switch(url) { case x.php : $("-sharpmenu").show(); break; } above is only to judge what url is and what to do but can I add get judgment? Do the same thing! is the same as $( "- sharpmenu...
var $buttom=[]; function addBtn() { var $dom = $( <button> + iPP + < button> ); $dom.on( click ,function(){ console.log($(this).html()); }); $buttom.push($dom); $.each($buttom,function(i,n){ ...
recently I have been practicing making a pop-up box, = [part 1] = put the code first: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compa...
I introduced menu.js " on the web site. <script type= text javascript src="js menu.js">< script> $abc = 123 ; <script type= text javascript src="js menu.js">< script> but suppose I have a value on ...
jq s ajax append after using the TouchSlide plug-in causes the class defined by TouchSlide to have no style now it s like this width0pxbdclass ajax ...
since my website does not use https, to access the login page of my website under firefox, firefox will clearly indicate that the link to this site is not secure and the login information entered will be stolen. I would like to ask, how can I change t...
<?foreach ($region_get_all->regions as $key):?> <?endforeach;?> suppose I get multiple numbers via foreach what I want to do is that when the user selects the "edit " data , I will show the div that there will be data , and wil...
$(".help_cover").mouseenter(function(event) { $(".layout_help_cover").fadeIn(); }); $(".help_cover").mouseleave(function(event) { $(".layout_help_cover").fadeOut(); }); how can I write this code? I think this ...
for example, there is a requirement that a person can add multiple internships, and I can click a button on the page to add form, for multiple internships. The content of this form is the same, and so is class. The json format of each form is {Id: "1 ...
my code structure is like this I think after on load, besides fadeOut, the js function on also stops and stop running. how can this be written? Update $(document).ready(function () { $(".pageloading").show(); var curIndex=0; ...
list of submit-sharpadd_form when ctrl+s or command+s is pressed $(window).bind( keydown , function(event) { if (event.ctrlKey || event.metaKey) { switch (String.fromCharCode(event.which).toLowerCase()) { case s : event.preventDef...
here is my method, which I think is too bulky and doesn t work well: $(function(){ $( body ).scrollspy({target: -sharpproductDetailsNav }); $(window).scroll(function() { ...
how to limit the display of only 10 news headlines after loading the list of news headlines in json? Because there are hundreds of pieces of news information in the json file, how to make it display only 10 pieces of news? <!DOCTYPE html> <htm...
mainly want to achieve a single multiple selection function, need to be met at the same time: 1, click any option can be selected, unchecked; 2, click custom option, can expand more content; 3, click other options, can hide more content because of cl...
var data = { "message":"", "error":"false", "human":[ { "title":"", "title_r...
such as the problem, the need is that after the page is loaded, the input automatically gets the focus and the soft keyboard pops up automatically. The problem now is: 1. Unable to pop up soft keyboard 2.ios iPhone browser cannot automatically get foc...
the css action has always been a part of what I want to learn. there are great gods who can share how to change the Fortress platoon to X, press X and then change it back to Fort platoon? https: www.snapchat.com snapchat mobile version has the s...