JS Learning Summary

Source: Internet
Author: User

The new Array () [] [] represents the array
The new object () {} {} represents the object

JavaScript Objects

Objects are separated by curly braces. Inside the parentheses, the properties of the object are defined in the form of name and value pairs (name:value). Attributes are separated by commas:

var person={firstname: "Bill", LastName: "Gates", id:5566};

The object (person) in the example above has three attributes: FirstName, LastName, and ID.

Spaces and lines do not matter. Declarations can span multiple lines:

var person={firstname: "Bill", LastName  : "Gates", id        :  5566};

Object properties are addressed in two ways:

name=person.lastname;name=person["LastName"];
Undefined and Null

Undefined This value indicates that the variable does not contain a value.

You can empty the variable by setting its value to null

Local Variables

A variable declared inside a JavaScript function (using VAR) is a local variable that can only be accessed inside the function. (The scope of the variable is local).

You can use a local variable with the same name in a different function, because only a function that declares the variable will recognize it.

As soon as the function is complete, the local variable is deleted.

Global Variables

Variables declared outside of a function are global variables, and all scripts and functions on a Web page can access it.

the lifetime of a JavaScript variable

The lifetime of JavaScript variables begins at the time they are declared.

Local variables are deleted after the function is run. Global variables are deleted after the page is closed.

Assigning a value to an undeclared JavaScript variable

If you assign a value to a variable that has not been declared, the variable is automatically declared as a global variable.

This statement: carname= "Volvo";

A global variable is declared carname, even if it executes within the function.

= = = (value and type) x===5 to true;x=== "5" is false

Triggering an instance through an event

<! DOCTYPE html>function  mOver (obj) {obj.innerhtml= "Thank You"}  function  mout (obj) {obj.innerhtml= "Move mouse over"}</script></body>

JS Learning Summary

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.