What is the difference in Javascript between 'undefined' and 'not defined'?

前端 未结 8 2219
半阙折子戏
半阙折子戏 2020-11-29 03:21

If you attempt to use a variable that does not exist and has not been declared, javascript will throw an error. var name is not defined, and the script will sto

8条回答
  •  萌比男神i
    2020-11-29 03:59

    alert(a);

    Here a is not defined.

    alert(a);
    var a=10;

    Here a is undefined because javascript engine convert this code to

    var a;
    alert(a); // that's why `a` is defined here 
    a=10;
    

提交回复
热议问题