Javascript programming (Lesson 3)

Source: Internet
Author: User

Javascript programming (Lesson 3)

The third lesson finally met you. Thanks to the hard work of Actions and the resources and tutorials provided by the Forum, I hope you can learn and improve them together.

If you have any comments, suggestions, or ideas, you can post them in the Q & A area of this edition or in the website management edition. We will give you feedback in time.

The following are the key points of today's learning:

A. Add the variable content of the course.

B. Basic syntax of the if statement

C.w.w.com () basic usage

A. Variables

1. Type rules of Variables

Javascript is non-typed, and its variables can put any data type value.

2. Variable Declaration

In javascript programs, you must declare a variable before using it. Variables are declared using the keyword var. In fact, you do not have to declare variables first. In some cases, variable declaration is optional.

Var I;

Var sum;

You can also use the var keyword to declare multiple variables;

Var I, sum;

You can also bind the variable declaration and variable initialization together:

Var message = hello;

Var I = 0, j = 0, k = 0;

Variables declared by var are permanent, because browsers have different attitudes towards whether global variables can be deleted (local variables can be deleted). To ensure security, it is best to assume that the global variable cannot be deleted.

You can use var to declare the same variable multiple times.

When you assign a value to an unspecified variable, which variable will js automatically use to create a global variable for you.

If you want to create a local variable in the function. Then, you must use var to declare it within the function.

3. Scope of Variables

If the names of local variables and global variables are the same, the local variables take precedence. Js does not have block-level scope. All variables declared in the function have the same scope.

Var x; // declare an unassigned variable whose value is undefined.

Alert (u); // using undeclared variables will cause an error.

U = 3; // If you assign a value to an undeclared variable, the variable is created.

4. Original and reference types

Var a = 3.14; // Original Type

Var B = a; // reference type

B. if statement

If (condition)

Statement segment 1

Else

Statement Segment 2

Function: If the expression is true, statement segment 1 is executed; otherwise, statement Segment 2 is executed.

Note:

The if-else statement is the most basic control statement in JavaScript. It can be used to change the statement execution sequence.

The relational statement must be used in the expression for judgment. It is estimated as a Boolean value.

It converts zero and non-zero numbers to false and true, respectively.

If the statement after if has multiple rows, you must enclose it with curly brackets.

Example

If (age <16)

Alert ("kids ");

Else

Alert ("adult ");

End if

If statement nesting

If (Boolean) Statement 1;

Else if (Boolean) Statement 2;

Else if (Boolean) Statement 3;

Else Statement 4;

In this case, the Boolean expression of each level is calculated. If it is true, the corresponding statement is executed. Otherwise, the else statement is executed.

C.domaincom () Usage

1. Basic syntax

Window. open (pageURL, name, parameters)

Where:

PageURL is the sub-window path

Name is the sub-window handle

Parameters is window parameters (parameters are separated by commas)

Example:

<Script language = "javascript">

<! --

Window. open (url) // url is a url, such as: http://www.numb1.com (absolute) or index.htm relative)

-->

</SCRIPT>

2. Window Parameters

Where yes/no can also use 1/0; value is a specific value, in pixels.

Toolbar = yes, no show toolbar

Location = yes, no show URL bar

Directories = yes, no whether the navigation bar is displayed

Status = yes, no whether the status bar is displayed

Menubar = yes, no whether to display the menu

Scrollbars = yes, no whether to display the scroll bar

Resizable = yes, no whether the announcement window size can be changed

Copyhistory = yes, no whether to display the history button

Width = the width of the value announcement window

Height = the height of the value announcement window

Left = value the upper left vertex of the announcement window is 100 pixels left of the screen

Top = the top left vertex of the value announcement window is 100 pixels from the top of the screen

Example:

<Script language = "javascript">

<! --

Window. open ("00000.html", "newwindow ",

"Toolbar = no, location = no, directories = no,

Status = no, menubar = no, scrollbars = no,

Resizable = no,

Copyhistory = no, width = 500, height = 500,

Left = 100, top = 100 ")

// -->

</Script>
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.