JS Basic Notes

Source: Internet
Author: User

JavaScript Objects

JavaScript objects are data that owns properties and methods

The following code sets the value for the variable car to "Fiat":

var car = "Fiat";

An object is also a variable, but an object can contain multiple values (multiple variables).

var car = {type:"Fiat", Model: $, color:"white"};
Object Definition
var person = {firstName:' John ', LastName:"Doe", Age:eyecolor:"Blue"};

Accessing Object Properties

Person.lastname;

person["LastName"];

Create JavaScript Object I

Creating JavaScript Objects II

Accessing Object Properties I

Accessing Object Properties II

function properties are accessed as a method

function properties are accessed as a property

JavaScript functions Local JavaScript variables

A variable declared inside a JavaScript function (using Var) is a local variable, so it can only be accessed inside the function. (The scope of the variable is local).

You can use local variables with the same name in different functions, because only the function that declares the variable can recognize the variable.

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

Global JavaScript 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 values to undeclared JavaScript variables

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.

JavascriptScope

Scopes can access a collection of variables.

JavaScript Scopes

In JavaScript, objects and functions are also variables.

In JavaScript, scopes are a collection of accessible variables, objects, and functions.

JavaScript function Scope: scope is modified within a function.

JS Basic Notes

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.