Home > Article > Web Front-end > Getting Started with JavaScript Programming (Lesson 3)_Basic Knowledge
Getting Started with JavaScript Programming (Lesson 3)
The third lesson is finally with you. Everyone would like to thank Actions for their hard work. Make good use of the resources and tutorials provided by the forum. I hope everyone can learn and improve together :D
If you have any comments, suggestions or ideas, you can post them in the tutorial Q&A area of this version or the suggestions or opinions in the site management version. We will give you feedback in time :)
Here are the key points of today’s study:
A. Supplement the variable content in class
B.Basic syntax of if statement
Basic usage of C.window.com()
A. Variables
1. Type rules for variables
Javascript is untyped, and its variables can hold values of any data type.
2. Declaration of variables
In a JavaScript program, you must declare a variable before using it. Variables are declared using the keyword var. In fact, it is not necessary to declare the variable first. In some cases, variable declaration is optional.
var i;
var sum;
You can also use a var keyword to declare multiple variables;
var i, sum;
You can also bind variable declaration and variable initialization together:
var message = hello;
var i = 0, j=0, k=0;
Variables declared by var are permanent, because each browser has different attitudes towards whether global variables can be deleted (local variables can be deleted). For safety, 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 an undeclared variable, js will automatically use that variable to create a global variable for you.
If you want to create a local variable inside a function. Then it must be declared inside the function using var.
3. Scope of variables
If local variables and global variables have the same name, the local variable takes precedence. js does not have block level scope. All variables declared in a function have the same scope.
var x; //Declare an unassigned variable, its value is undefined.
alert(u); //Using undeclared variables will throw an error.
u=3; //Assigning a value to an undeclared variable will create the variable.
4. Primitive types 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, execute statement segment 1; otherwise, execute statement segment 2.
Description:
The if -else statement is the most basic control statement in JavaScript, through which the execution order of statements can be changed.
Relational statements must be used in the expression to implement judgment, and it is evaluated as a Boolean value.
It converts zero and non-zero numbers into false and true respectively.
If the statement after if has multiple lines, it must be enclosed in curly braces.
Example
if (age alert("Children");
else
alert("Adult");
end if
Nesting of if statements
if (Boolean value) statement 1;
else if (Boolean value) statement 2;
else if (Boolean value) statement 3;
else statement 4;
In this case, the Boolean expression at each level will be calculated. If it is true, its corresponding statement will be executed, otherwise the statement after else will be executed.
Usage of C.window.com()
1. Basic grammar
window.open(pageURL,name,parameters)
Among them:
pageURL is the sub-window path
name is the child window handle
parameters are window parameters (each parameter is separated by commas)
Example:
2. Window parameters
You can also use 1/0 for yes/no; value is a specific value in pixels.
toolbar=yes,no Whether to display the toolbar
location=yes,no Whether to display the URL bar
directories=yes,no Whether to display the navigation bar
status=yes,no Whether to display the status bar
menubar=yes,no Whether to display the menu
scrollbars=yes,no Whether to display scroll bars
resizable=yes,no Whether the size of the announcement window can be changed
copyhistory=yes,no Whether to display the history button
width=value The width of the announcement window
height=value The height of the announcement window
left=value The upper left vertex of the announcement window is 100 pixels from the left side of the screen
top=value The upper left vertex of the announcement window is 100 pixels from the top of the screen
Example:
<script>
<br><!--
<br>window.open (’url’) //url为一网址,如:http://www.numb1.com(绝对) 或 index.htm相对)
<br>-->
<br></script><script>
<br><!--
<br>window.open("00000.html","newwindow",
<br>"toolbar=no,location=no,directories=no,
<br>status=no,menubar=no,scrollbars=no,
<br>resizable=no,
<br>copyhistory=no,width=500,height=500,
<br>left=100,top=100")
<br>//-->
<br></script>