Getting Started with zero Basics JavaScript (2)

Source: Internet
Author: User

In the last study, I haveJavaScriptwith a certain basis of understanding, such as:JavaScript's history,JavaScriptThe names of the variables, the various operators, and the types of data and conversions between them. And there are some of the most basic statements,If-else,Switch-case, forLoops, whileloops, and the nesting relationships between them. The nesting relationships in these statements need to be well understood, as it is seldom possible to compile with just one statement in true development. In addition, when a lot of nested relationships are complex, beware of confusion, as long as there is a curly brace to write the wrong position, it can lead to the overall loss of the phenomenon, there may be a dead loop, so in the nesting process, we must maintain a clear idea. A layer of nesting to write clearly, if even we ourselves have been our own code to dry, after the completion of the program to the leadership to see not be sprayed into the husky? So at this stage we are going to develop a habit of gill, if we useWebstormIf you are programming, you can usectrl+alt+lto Auto-Gill. In addition, we finally mentioned in the last blog of arrays and functions, this time I will continue the last content, to drill down on arrays and functions, the theory of a condom to pay for the actual action. Before the leadership, this theory of things you will say no more useless, only to come up with a real project to convince others. Low-key high-profile work.

1. four forms of the function

All functions can be divided into non-parameter non-return values of the function ( more useful ) , no parameter has a return value of the function, there is no return value of the function, there is a parameter return value ( the actual use of the most ) these four kinds.

2. Overloading of functions

The so-called overloading is the same as the function name, but the number of formal parameters of the function is different, or the data type of the formal parameter is different, which makes the function overloaded. In our JavaScript there is no function overload, and if there is a function with the same name, then the function above will cover the previous function.

In JavaScript, scopes are broadly divided into two types, global scope and local scope.

3. global scope and local scope

A function is a local scope, and a variable within a local scope is called a local variable.

The area between the script tags in the same page is called global scope.

Variables in the global scope can be accessed anywhere, called global variables.

Variables defined within the global scope are global variables that can be accessed anywhere in the page ( including inside the function ).

Variables defined within the function that do not use var are also global variables.

var fun = function (A, b) {
return a-B;
};

Such a function without a name, like the assignment operator, is called an anonymous function. It is generally used when binding events. An anonymous function defines a function in the form of a function expression.

callback function: The function is passed as a parameter

4. How a function is declared differs from a function expression
    1. function has a name in its declaration
    2. A function in a function expression has no name, is an anonymous function, and the name of the preceding variable can be regarded as the name of the function.
    3. When a function is pre-parsed, the function declaration is first advanced to the front of the scope, and the function expression does not elevate
    4. Functions in a function declaration can be called before a declaration, but functions of a function expression must be called after the function expression.

In our JavaScript , before the program actually executes, all the code is scanned once, the declaration of the variable, the declaration of the function, and the elevation of the parameter to the front of the current scope. This is called pre-parsing of functions.

5. self-executing functions

A self-executing function is a non-named function that defines the functions that are called immediately, and this function is generally called only once.

function: self-executing functions do not have a name, so in many cases it is possible to avoid duplicate function names in some large projects.

There are two kinds of data types in Js, simple data type:number,string,boolean,null,undefined

Complex data type: Object date,array,function.

6. built-in objects for functions

The built-in object of the function represents the object that the system has already defined for us.

For example , the Math object is a system that encapsulates a mathematical operation into a single object.

Methods and functions are actually one thing, except that the function is in the object or through the object . the way to invoke, we call the method.

6.1Math Objects

 

6.2Date Objects

6.3Array Objects

7. three ways to empty an array

Getting Started with zero Basics JavaScript (2)

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.