JS Basic question

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.