Javascript Note 1. js and basic json instructions _ javascript skills

Source: Internet
Author: User
The data in JavaScript is concise. Simple data only includes undefined, null, boolean, number, and string, and complex data contains only one type, namely, object. The code in JavaScript is only reflected in one form, that is, function.

Note: The above words are in lower case. Do not confuse them with JavaScript built-in functions such as Number, String, Object, and Function. The JavaScript language is case sensitive.

Typeof (null) returns an object, but null is not an object.

JavaScript code has only one function form, and function is the function type. Functions are written in the form of "Definition" and "variable ".

The defined function statements are executed first. After the function definition is executed, other statement code is executed in sequence. JavaScript is executed in segments.

Let's take a look at the following code:

The Code is as follows:


Var myfunc = function ()
{
Alert ("hello ");
};
Myfunc (); // call myfunc for the first time and output hello
Myfunc = function ()
{
Alert ("yeah ");
};
Myfunc (); // The second call to myfunc will output yeah



The result of the program running tells us that after the first function call, the function variable is assigned a new function code body, so that different outputs appear when the function is called for the second time.

Now, let's change the above Code to a defined function:

The Code is as follows:


Function myfunc ()
{
Alert ("hello ");
};
Myfunc (); // call myfunc here and output yeah instead of hello
Function myfunc ()
{
Alert ("yeah ");
};
Myfunc (); // call myfunc here, of course, output yeah



The two functions with identical signatures should be invalid in other programming languages. But in JavaScript, that's right. The JavaScript execution engine does not analyze and execute programs one by one, but analyzes and executes programs one by one. Before calling myfunc for the first time, the Code logic defined by the first function statement was overwritten by the second Function Definition Statement. Therefore, the last function logic is executed for both calls.

Create object

The Code is as follows:


Related Article

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.