JS Basic Interview
1. Variables declared after use
2. Global variables and local variables
<script> var str = ' global '; function T () { alert (str); var str = ' local '; // ndefined alert (str); } T (); // undefined,local var str = ' global '; if (true) { var str = ' local '; } alert (str);//local</script>
JS Function Basics
function declaration Variable Promotion
expression function definition
function Body Statement block
This
Function prototype
function instance
<script>functionfoo () {getname=function() {Alert (3)}; return This; } foo.prototype.getname=function() {alert (' Prototype.getname '); }; //var foo = function () { //alert (2); // } //function foo () { //alert (2.2); // } //foo ();//2 //foo (). GetName () //new Foo (). getname ();//prototype.getname New NewFoo (). GetName ();//Prototype.getname //executes the new Foo () and becomes the instance object of new Foo. GetName (), //the instance object of Foo is then executed. GetName (), back to the mode 3 function block, the result is "Google", //finally executes the instance object of new Foo. </script>
JS Basic question