[Youpol] basic JS content arrangement (2), Pol js

Source: Internet
Author: User

[Youpol] basic JS content arrangement (2), Pol js

I. JavaScript Variables

JS variable standards

(1) The variable must contain letters

(2) It can start with $ and _, but is not recommended.

(3) variables are case sensitive.

 

JavaScript uses var to declare Variables

For example, var carname = "Volvo ";

 

Value = undefined variables are often declared in computer programs. A variable declared without a value. Its value is actually undefined.

Ii. JavaScript Data Types

String numeric Number Boolean Array Object

Null Undefined

 

JavaScript Array

Var cars = new Array ("Saab", "Volov", "BMW ");

Var cars = ["Saab", "Volov", "BMW"];

Array subscript is based on 0

 

JS object

There are two addressing methods for object attributes:

Document. write (person. lastname + "<br> ");

Document. write (person ["lastname"] + "<br> ");

 

Declare variable type

When you declare a new variable, you can use the keyword "new" to declare its type:

Var carname = new String;
Var x = new Number;
Var y = new Boolean;
Var cars = new Array;
Var person = new Object;

JavaScript variables are all objects. When you declare a variable, a new object is created.

 

Survival of JavaScript Variables

The lifecycle of JavaScript variables starts from the time they are declared.

 

Local variables will be deleted after the function is run.

 

Global variables will be deleted after the page is closed.

 

JavaScript Functions

 

Syntax

Function functionname ()

{

// Execute the code

}

Call a function with Parameters

Function functionname (argument1, argument2)

{

// Execute the code

}

 

Functions with return values

Function myFuntion ()

{

Var x = 5;

Return x;

}

 

Tomorrow's content

JS scope Js event JS string JS operator JS comparison

 

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.