Java Script Programming Start (Third lesson) _ Basics

Source: Internet
Author: User
The third lesson finally and everyone to meet, we would like to thank the hard work, ah, make good use of the forum to provide resources and tutorials, I hope that we learn to improve:D
You have any comments, suggestions or ideas, you can go to this edition of the tutorial question or management version of the suggestions or comments to publish, we will give you feedback in time:)

Here are the highlights of today's study:
A. Content of the variable to supplement the class
Basic syntax for B.if statements
C.window.com () Basic usage

A. Variables
1. The type rule of the variable
Java script is of no type, and his variables can be placed in any data type value.
2. Declaration of variables
In a Java script program, you must declare a variable before you can use it. Variables are declared using the keyword var. In fact, you don't have to declare a variable first, and in some cases the variable declaration is optional.
var i;
var sum;
You can also declare multiple variables using a var keyword;
var i,sum;
You can also bind variable declarations and variable initializers together:
var message = ' Hello ';
var i = 0,j=0,k=0;
Variables declared by Var are permanent because each browser has a different attitude to whether global variables can be deleted (both can be removed) for security, it is best to assume that global variables cannot be deleted.
You can use Var to declare the same variable multiple times
When you assign a value to a variable that is not declared, JS automatically uses which variable to create a global variable for you.
If you want to create a local variable inside the function. Then you must declare it in the function with Var.
3. Scope of variables
If the local variable and the global variable have the same name, the local variable takes precedence. JS does not have a block-level scope. All the variables declared in the function are the same scope.
Var x;//declares an unassigned variable whose value is undefined.
alert (u); Using an undeclared variable throws an error.
u=3;//to assign a value to an undeclared variable will create the variable.
4. Original type and reference type
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, the statement segment 1 is executed, otherwise the statement segment 2 is executed.

Description
The If-else statement is the most basic control statement in JavaScript, which allows you to change the order in which statements are executed.
In an expression, you must use a relational statement to implement the judgment, which is evaluated as a Boolean value.
It converts 0 and nonzero numbers to false and true respectively.
If the statement after if has more than one line, you must enclose it with curly braces.

Example
if (age < 16)
Alert ("Children");
Else
Alert ("adult");
End If

Nesting of IF statements
if (Boolean) statement 1;
else if (Boolean) statement 2;
else if (Boolean) statement 3;
Else Statement 4;
In this case, each level of the Boolean expression will be computed, if true, then execute its corresponding statement, otherwise execute else after the statement.

Use of c.window.com ()
1. Basic grammar
window.open (Pageurl,name,parameters)
which
Pageurl as a child window path
Name is a child window handle
Parameters for window parameters (comma-separated arguments)
Cases:
<script language= "java SCRIPT" >
<!--
window.open (' url ')//url as 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 as a specific value, the unit pixel.
Toolbar=yes,no whether the toolbar is displayed
Location=yes,no whether to display the URL bar
Directories=yes,no whether to show the navigation bar
Status=yes,no whether the status bar is displayed
Menubar=yes,no whether to display menus
Scrollbars=yes,no whether scroll bars are displayed
Resizable=yes,no Whether you can change the size of the announcement window
Copyhistory=yes,no Whether the history button is displayed
Width=value the width of the announcement window
Height=value the height of the announcement window
The top left vertex of the Left=value announcement window is 100 pixels to the left of the screen
The top left vertex of the Top=value announcement window is 100 pixels above the screen
Cases:
<script language= "java Script" >
<!--
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>

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.