"Excellent Boer" JS basic content finishing (2)

Source: Internet
Author: User

First, JavaScript variables

The standard for JS variables

(1) The variable must be in the letter

(2) can start with $ and _ but not recommended

(3) variable-to-case sensitivity

JavaScript declares variables with Var

For example: Var carname= "Volvo";

Value = undefined in a computer program, variables that are not valued are often declared. A variable that is not declared with a value, whose value is actually undefined.

Ii. JavaScript data types

String String Numeric Number Boolean Boolean array of Array Object object

Null null undefined Undefined

JavaScript arrays

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

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

The array subscript is based on the 0

JS Object

Object properties are addressed in two ways:

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

document.write (person["LastName"] + "<br>");

Declaring variable types

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 objects. When you declare a variable, a new object is created

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.

Functions of JavaScript

Grammar

function functionname ()

{

Execute code

}

Calling a function with parameters

function functionname (ARGUMENT1,ARGUMENT2)

{

Execute code

}

function with return value

function Myfuntion ()

{

var x=5;

return x;

}

Tomorrow's Content

JS's scope JS event js string js operator js Comparison

"Excellent Boer" JS basic content finishing (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.