Basic Javascript learning notes (for cainiao)

Source: Internet
Author: User
The following small series will bring you a basic Javascript study note (cainiao must read ). I think this is quite good. Now I will share it with you and give you a reference. Let's take a look at what variables are?

A variable is a container used to store information.

Variable Declaration

Syntax:

Var variable name

Variable name = value;

The variable must be declared before being assigned a value.

Variable values can be assigned repeatedly.

Variable naming rules

The variable must start with a letter;

Variables can also start with $ and _ (but we do not recommend this );

Variable names are case sensitive (a and A are different variables ).

Statement

The statement ends with a semicolon. If the semicolon is omitted, the end of the statement is determined by the parser.

There is a good coding habit, all should end;

Data Type

In JavaScript, a piece of information is a value ). Values have different types. The most familiar type is numbers. The string value is enclosed in

One or more words in quotation marks.

Any numeric value. A number can contain a decimal point or 68.57

Character in string quotation marks. You can use single or double quotation marks "hello, world"

Boolean value (Boolean) true or false true

Undefined and Null Undefined indicate that the variable does not contain any value. You can clear a variable by setting its value to null.

Any value associated with the object

Value returned by the function

1 var a; // a is undefined2 var a = 6; // a is the number 3 var a = "Jason"; // a is the string

What is a function?

A function is a set of JavaScript statements that execute a task.

Basic Syntax:

Function Name () {function Code ;}

Function Name ();

Note:

Function defines the function keywords.

"Function name": the name you use for the function.

Replace "function code" with code that completes a specific function.

"Second function name"

1 function add2 () {2 var sun = 3 + 2; 3 alert (sun); 4} 5 add2 (); // call the function and write the function name directly to bring up the function code.
12
 

Output content (document. write)

Document. write () directly outputs content on the webpage.

First, the output content is enclosed by "" and the content in "" is directly output.

document.write("I love JavaScript!");

Type 2: Output content through Variables

Var mystr = "hello world"; document. write (mysrt); // directly write the variable name and output the content stored in the variable.

Third: Output multiple items and connect the content with the "+" sign.

Var mystr = "hello"; document. write (mystr + "I love Java Script"); // connect multiple contents with a plus sign

Type 4: Output HTML tags and take effect. The tags are enclosed.

Var mystr = "hello"; document. write (mystr +"
"); // Output" hello ", output a linefeed document. write (" JavaScript ");

Warning (alert message dialog box)

When we visit a website, a small window pops up with a prompt message. If you do not click "OK", you cannot do anything on the webpage.

This small window is implemented using alert.

Syntax: alert (string or variable );

var mynum = 30;alert("hello!");alert(mynum);

Result: the message box is displayed in order (the alert message dialog box contains a confirmation button)

Note:

1. You cannot perform any other operations before clicking "OK" in the dialog box.

2. message dialog boxes can be used to debug programs.

3. alert output content, which can be a string or variable, similar to document. write

Confirm selection (confirm message dialog box)

In addition to providing information to users, we also want to obtain information from users. The confirm message dialog box is used.

The confirm message dialog box is usually used to allow users to select actions, such as: "Are you right ?" . A dialog box (including a confirmation button and a Cancel button) is displayed ).

Syntax: confirm (str );

Parameter description: str: Return Value of the text to be displayed in the message dialog box: Boolean

Return Value:

Returns true if you click OK.

If you click "cancel", false is returned.

Note: the return value can be used to determine the button clicked by the user.

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.