On the problem of variable lifting in functions

A title goes like this:

var a=2;
function f() {
  console.log(a);
  var a=3;
}  
f();// undefined
f(4);// undefined

Why are f () and f (4) undefined? Isn"t this variable promotion

Feb.28,2021

  • f () : yes, it has been promoted, so there is an in the f function when console.log () is executed, and it will not be found in the external scope. When console.log () is executed, it is only declared and not assigned, so it is undefined
  • .
  • f (4) : your function has no formal parameters defined at all, and there is no internal use of arguments variables, so passing everything is the same as not passing anything, which is equivalent to f ()
  • .
< hr >
  1. arguments will receive all the parameters you pass in, regardless of whether or not you have defined them or how many.

    
    

    f();

        var a=2;
        function f() {
          var a; // 
          console.log(a);
          var a=3;
        }

    f (4):
    your f () has no defined parameters, which is the same as f ()

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3301e-34227.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3301e-34227.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?